setSpriteLocation()
Purpose
Position a sprite on the screen
Description
Set the horizontal and vertical position of a sprite
Syntax
setSpriteLocation( sprite, pos )
setSpriteLocation( sprite, xpos, ypos )
sprite.x = xpos; sprite.y = ypos
Arguments
sprite handle of the created sprite
pos horizontal and vertical position on the screen in pixels { x, y }
xpos horizontal position on the screen in pixels
ypos vertical position on the screen in pixels
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, { 8, 8 } )
loop
clear()
c = controls( 0 )
printAt( 0, 0, "Use left joystick to control sprite" )
setSpriteSpeed( ship, { 480 * c.lx, -480 * 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
updateSprites()
drawSprites()
update()
repeat
Associated Commands