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:

whenclickedforevergotoxmousex/...y:mousey/...wheretheamountvariableishowmuchthespritemoveswith1beinggoingtomousexandmouseyandinfinitystayingat0,0.end

A handy parallax custom block can be made using the following code:

defineParallaxamountgotoxmousex/amounty:mousey/amount

To use this parallax engine, put the following code in the back sprite

whenclickedforeverParallax20end

And then in the middle sprite

whenclickedforeverParallax10end

And in the front sprite

whenclickedforeverParallax5end

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:

defineParallaxamountxygotoxmousex/amount+xy:mousey/amount+y

And here's an example of how it can be used:

whenclickedsetxto240setyto0setspeedto2Parallax20xychangexbyspeed*-1repeatuntilxposition<-240Parallax20xychangexbyspeed*-1

This code would make a sprite start on the right side of the screen and move to the left side.

See Also