getSpriteSpeed()
Purpose
Set a sprites speed
Description
Set a sprites horizontal and vertical speed. This is the amount that the sprite is moved by in each axis when updatesprites is called
Syntax
speed = getSpriteSpeed( sprite )
xspeed = sprite.x_speed; yspeed = sprite.y_speed
Arguments
sprite handle of the created sprite
speed vector containg the horizontal and vertical speeds { x, y }
xspeed amount to add to the x position of the sprite at each updatesprites call
yspeed amount to add to the y position of the sprite at each updatesprites call
Example
radians( true )
image = loadImage( "Untied Games/Enemy small top C", false )
ship = createSprite()
setSpriteImage( ship, image )
lastpos = { gWidth() / 2, gHeight() / 2 }
setSpriteLocation( ship, lastpos )
setSpriteScale( ship, { 4, 4 } )
loop
clear()
c = controls( 0 )
printAt( 0, 0, "Use left joystick to control sprite" )
setSpriteSpeed( ship, { 600 * c.lx, -600 * c.ly } )
curpos = getSpriteLocation( ship )
if curpos != lastpos then
setSpriteRotation( ship, -pi / 2 + atan2( curpos.y - lastpos.y, curpos.x - lastpos.x ) )
lastpos = curpos
endIf
sv = getSpriteSpeed( ship )
speed = sqrt( sv.x * sv.x + sv.y * sv.y )
printAt( 0, 1, "speed ", int( speed ) ) // print current speed
updateSprites()
drawSprites()
update()
repeat
Associated Commands