setSpriteOrigin()
Purpose
Change the origin point of a sprite
Description
By default the origin of a sprite (0, 0) is the centre. This function allows you to change it to be, for example, the top left
Syntax
setSpriteOrigin( sprite, pos )
setSpriteOrigin( sprite, xpos, ypos )
Arguments
sprite handle of the sprite
pos horizontal and vertical origin position relative to the centre { x, y }
xpos horizontal origin position relative to the centre
ypos vertcal origin position relative to the centre
Example
image = loadImage( "Untied Games/Enemy A", false )
enemy = createSprite()
setSpriteImage( enemy, image )
setSpriteAnimation( enemy, 0, 4, 20 )
setSpriteLocation( enemy, { 0, 0 } )
size = getSpriteSize( enemy )
setSpriteScale( enemy, { 8, 8 } )
loop
clear()
origin = getSpriteOrigin( enemy )
printAt( 20, 10, "Sprite origin x = ", origin.x, " y = ", origin.y )
printAt( 20, 11, "Press A to move origin to the top left" )
printAt( 20, 12, "Press B to move origin to the centre" )
c = controls( 0 )
if c.a then
setSpriteOrigin( enemy, { -size.x / 2, -size.y / 2 } )
endIf
if c.b then
setSpriteOrigin( enemy, { 0, 0 } )
endIf
updateSprites()
drawSprites()
update()
repeat
Associated Commands