(Redirected from Eng:Change Y by ())
|Change Y by ()|
Often in games, the player controls a sprite and moves it around, such as with velocity. In this way, the Change Y by () block (and the Change X by () block) can become very useful. The y axis ranges from -180 to 180.
- In this script, which could control a paddle in Pong, a yVelocity variable controls the sprite's up and down movement. This allows the sprite to accelerate and decelerate.
set [yVelocity v] to  forever if <key [up arrow v] pressed?> then change [yVelocity v] by (2) end if <key [down arrow v] pressed?> then change [yVelocity v] by (-2) end change y by (yVelocity) if <(yVelocity) > > then change [yVelocity v] by (-1) end if <(yVelocity) < > then change [yVelocity v] by (1) end end
- Main article: List of Block Workarounds
This block can be replicated with the following scripts:
set y to ((y position) + (change)) go to x: (x position) y: ((y position) + (change)) define change y by (value) //run without screen refresh set [pastDirection v] to (direction) point in direction (0 v) move (value) steps point in direction (pastDirection)