Parallax

Материал из Поле цифровой дидактики

Шаблон:Wiki Standards A parallax is a project on which the user controls a background by moving their mouse. Mostly these projects are created so the user can relax and view the sunset or anything else. Sometimes people just like to show off their art in a parallax project.Шаблон:Citation needed

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 handy 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. This could be used for things like a bird moving across the sky, a sprite walking across the screen, etc. Here's what the custom block looks like:

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

And here's an example of how it 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.

See Also