Mouse Scrolling
Mouse scrolling is a form of scrolling, but can be simpler due to there being less code required than regular scrolling.
Mouse Scrolling Engine
Setting Up
To set up the project with the ability to scroll using only a mouse pointer, two sprites, and four variables are needed. The four variables required are the following:
After creating these variables, the two sprites need to be created. The map and the character. The map can be made of any size. If the map sprite cannot get very large, please refer to this to learn how to bypass the size limit.
Coding
Coding the Map
For coding the map of the project, the following code is needed:
Coding the Player
The scripts are as shown:
Adding Objects To Scrolling Games
Sometimes in a scrolling game, interactive objects are added. The block can be used but the object(s) will just stay right on the screen. Here are a couple different methods on how to put objects in a set location on a scrolling game:
A Singular Object
In order to have a single object stay in place on a scrolling game, a certain code is needed to that the object will not stick to a set location on the screen. First, only 2 local variables are needed:
Once you have those required variables, all you need to do now is give the object the code that will make it stay in one location (not on the screen) and will give it the ability to go on and off the screen:
Cloning The Same Object
The other way to add multiple objects to a project is by cloning them. For this sprite, the x and y variable are needed.
A custom block is the preferred method for cloning the sprite to prevent errors in the coding:
Then for the positioning for the clones objects, it is the same thing as the singular object except replace the with
hat block: