|Glide () Secs to X: () Y: ()|
glide () secs to x: () y: ()
The Glide () Secs to X: () Y: () block is a Motion Block and a Stack Block. The block moves its sprite steadily to the specified X and Y position in the specified amount of seconds - this is like pointing the sprite in a direction and repeatedly using Move () Steps, but with more precision. A disadvantage of the glide block, however, is that it pauses the script while the sprite is moving, preventing the script from doing other things while the sprite is gliding. Also, a glide can only be interrupted by a stopping scripts block, and the If on Edge, Bounce block will fail to work its intended function while a sprite is gliding.
The block is used whenever a sprite needs to glide - some common uses are:
- Fish moving in a tank
forever glide (pick random (1) to (2)) secs to x: (pick random (-240) to (240)) y: (pick random (-100) to (100))
- Obstacle sprites are created and glide toward the edge of the screen, as in Frogger
when I receive [StartCars v] hide set x to (240) repeat until <(gameOver) = > create clone of [myself v] wait (3) secs end when I start as a clone show glide (5) secs to x:(-240) y:(y position) delete this clone
- Falling objects
set y to (180) glide (1) secs to x:(x position) y:(-180)
- A sprite moving to another
glide (1) secs to x: ([x position v] of [Sprite2 v]) y: ([y position v] of [Sprite2 v])
Side-by-side Comparison of the Glide() and Move() Steps Blocks
This script uses the Move () Steps block to steadily move the sprite from the left edge to the right edge in eight seconds.
set x to (-240) repeat (80) move (6) steps wait (0.1) secs end
This script does the same thing by gliding.
set x to (-240) glide (8) secs to x:(240) y:(y position)
Gliding with Ease Out Effect
The Glide block uses a purely linear tweening method, meaning that the sprite's motion does not ease in or out. However, it is fairly easy to replicate the "ease out" effect that is heavily used in graphic design, where the object slows down as it approaches its target.
when I receive [tween v] repeat until <<([abs v] of ((target x) - (x position))) < [.25]> and <([abs v] of ((target y) - (y position))) < [.25]>> change x by (((target x) - (x position)) / (2)) change y by (((target y) - (y position)) / (2)) end go to x: (target x) y: (target y)
Alternatively, the following script can be used, which, as well as doing an ease out effect, allows choosing how long it should take to get to the wanted position. The 200 is the position (In this case, in the X-axis) which the sprite should glide to. The two X position blocks could be replaced by the Y position one if the sprite needs to move on the Y-axis. The number 10 is the number of seconds taken to reach the position multiplied by 10.
when I receive [tween v] repeat until <(round (x position)) = > change x by (((200) - (x position)) / (10)) end
Move () Steps • Turn Right () Degrees • Turn Left () Degrees • Go to () • Go to X: () Y: () • Glide () Secs to () • Glide () Secs to X: () Y: () • Point in Direction () • Point Towards ()• Change X by () • Set X to () • Change Y by () • Set Y to () • If on Edge, Bounce • Set Rotation Style () • X Position • Y Position • DirectionMore blocks...