A parallax is a project on which the user controls the viewer’s perspective of a backdrop 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
    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.

The following custom block defines the range of movement of each separate sprite - which acts as a singular layer - against the overall backdrop.

define Parallax (amount)
go to x((mouse x)/(amount)) y: ((mouse y) / (amount)) //The higher the value, the lower the range of movement. 

To recreate the proportionate movement of far and near objects, the block’s value should increase when moving from the front-most to back-most layers.

Parallax Effect On Moving Sprite

To retain the effect on a moving sprite, the following block can be used.

define Parallax (amount) (x) (y)
go to x(((mouse x)/(amount)) + (x)) y: (((mouse y) / (amount)) + (y))

The below script is an example of the block’s implementation. A sprite is moved across the screen from the right, while making minor adjustments to its position based on the mouse’s movement:

when green flag clicked
set [x v] to [240]
set [y v] to [0]
set [speed v] to [2]
repeat until <(x position) \< [-240]>
    Parallax [20] (x) (y)::custom
    change [x v] by ((speed) * [-1])

See Also

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