![]() |
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. (July 2022) Reason: Not formal enough |
A parallax is a project on which the user controls a background by moving the mouse.
Making a Parallax
When creating a parallax, the art must be broken up into different sprites, and the sprites must be layered to create an image. Once the sprites have been created, use the following script to create the parallax effect:
When green flag clicked forever go to x((mouse x)/(. . .::grey)) y: ((mouse y) / (. . .::grey))// where the amount variable is how much the sprite moves with 1 being going to mouse x and mouse y and infinity staying at 0,0. end
A parallax custom block can be made using the following code:
define Parallax (amount) go to x((mouse x)/(amount)) y: ((mouse y) / (amount))
To use this parallax engine, put the following code in the back sprite
When green flag clicked forever Parallax [20]::custom end
And then in the middle sprite
When green flag clicked forever Parallax [10]::custom end
And in the front sprite
When green flag clicked forever Parallax [5]::custom end
Parallax Effect On Moving Sprite
Sometimes a parallax effect on a moving sprite is desired. The custom block is:
define Parallax (amount) (x) (y) go to x(((mouse x)/(amount)) + (x)) y: (((mouse y) / (amount)) + (y))
The following script is an example of how the above script can be used:
when green flag clicked set [x v] to [240] set [y v] to [0] set [speed v] to [2] Parallax [20] (x) (y)::custom change [x v] by ((speed) * [-1]) repeat until <(x position) \< [-240]> Parallax [20] (x) (y)::custom change [x v] by ((speed) * [-1])
This code would make a sprite start on the right side of the screen and move to the left side.