Document stub.png This article or section may not have content matching Scratch Wiki editing standards. Please improve it according to Scratch Wiki:Guidelines and Scratch Wiki:Editing Conventions. (December 2020)

Top down scrollers are a very common type of game in Scratch as they are generally easy to make. A top down scroller consists of a scrolling map with walls and objects. There is a player that moves around the map and can be blocked by walls and other obstacles. There can be weapons, enemies, collectables or even inventory systems.

Scrolling

First, a scrolling base is needed (please note that there will be no walls yet). It can be made by drawing levels or by uploading images. If the player is being drawn, try to use vector, then convert to bitmap to trim of the edges (this is very important). Do not put any wall or obstacles as that will be for the wall sprite. (if a picture is being uploaded then it can be kept. Once the levels are done, label them for easier scripting. The middle one should be 0,0, the one on the right should be 1,0, and so on. Then make a player, it should be about 50 x 50 pixels big.

Making the scripts

Make 2 variables in the player sprite and make sure that they are for all sprites.

 (scroll x) 
(scroll y) 

Then go to the map and make these local variables and this custom block:

 (x)
(y) 
 define clone at (x) (y) (costume) 
set [x v] to ((0) - ((x) * (480)))
set [y v] to ((0) - ((y) * (360)))
switch costume to (costume)
create clone of (myself v)

Then, put the when green flag clicked block and create a clone block at the desired location and the correct costume all the way through all the map costumes. Use the labels as guides to what number to put. Make sure to put a wait 0.01 seconds block before just so the clones don't get deleted right when they are cloned (by the last script in this section)

Then make this script:

when I start as a clone
forever
 go to x: ((scroll x) - (x)) y: ((scroll y ) - (y))
 if <<(x position) = ((scroll x) - (x))> and < (y position) = ((scroll y) - (y)) >> then
  show
 else
  hide
 end
end 

Before moving on, add this script to prevent clones from stacking on top of each other:

when green flag clicked
delete this clone

Player Movement

Once the map is done, a movement system that has wall sensing and scrolling is needed. To begin, duplicate the map sprite but name it wall. Then add walls and obstacles. Finally delete the map, leaving just the obstacles. If an exported image is being used here, redraw the wall's shape (don't waste time drawing the insides) and set ghost effect to 100. Do not use the hide block for this. It's also possible to make it sense the color of the walls if the image has walls of the exact color.

Making the scripts

Start by making this script in the player sprite:

when green flag clicked
go to x:(0) y:(0)
forever
 if <key (up arrow v) pressed> then
  change y by (10) //or whatever you want to player speed to be (4 is slow, 8 is normal, 15 is fast)
  if <touching (wall v)> then
  change y by (-10) // or whatever you put in the top
  end
 end
 if <key (up arrow v) pressed> then
  change y by (-10) //do the negative of what you put for the up movement 
  if <touching (wall v)> then
  change y by (10) //same as previous
  end
 end
 if <key (up left arrow v) pressed> then
  change x by (10) 
  if <touching (wall v)> then
  change x by (-10)
  end
 end
 if <key (up right arrow v) pressed> then
  change x by (-10) 
  if <touching (wall v)> then
  change x by (10)
  end
 end
 change [scroll x v] by ((0) - (x position))
 change [scroll y v] by ((0) - (y position))
 go to x: (0) y: (0)
end

That is all the scripts for player movement and wall detection.

Getting Advanced

The scripts above are just for starting, here are some advanced ways to make it more fun.

Enemies

Enemies are entities that try to kill the player. To make an enemy, combine the scripts of the player and the walls, and add some more code. To do this, duplicate the player sprite, but delete the ending 3 blocks. Then, get the cloning scripts from the walls, and the rest is customizable. There are many type of enemies, including basic ones that glide straight to the player, advanced ones that identifies a path to the player, and semi-advanced ones that are a combination of both. They are harder to make, so it they are not included in this tutorial.

Achievements

Achievements are rewards achieved by completing specific tasks. Achievements can vary greatly, so it the types of achievements in each game is customizable. to decide what to make. However, an achievement needs a trigger, such as getting a certain number of coins or winning a level in hardcore.

Collectables

Collectables are items that can be collect, usually in the form of a currency that can be traded for items. They can also be skill points that increase the player's level. It can also be pieces that the player need to collect in order to win a level.

Finishing Up

Once all wanted features for the game is completed, the project can be shared with the community. Top down scrollers are very common, but they vary greatly. Before making it official, make sure it has no obvious glitches or bugs

Cookies help us deliver our services. By using our services, you agree to our use of cookies.