Hey, so yeah I can’t remember how to use these lol. I’m trying to animate my player sprite by rotating it but when I rotate it at a 45 degree angle, it rotates from whatever center point i don’t want. I can’t remember how I use translation I believe to correct this so it rotates around the center of the sprite.
Here’s an example where a sprite rotates under your finger wherever you touch the screen
Basically translate to the position, rotate, translate back
-- RotationAroundPoint
function setup()
end
function draw()
background(40, 40, 50)
local pos = CurrentTouch.pos
rotateAround(pos, ElapsedTime * 100)
sprite("Tyrian Remastered:Boss D", pos.x, pos.y)
end
function rotateAround(pos, angle)
translate(pos.x, pos.y)
rotate(angle)
translate(-pos.x, -pos.y)
end
@Programmer1500 - also remember rotate is additive, so multiple rotates in a draw function add up. Your not starting from the zero poi t with each rotation - its from the last angle you used.
displayMode(FULLSCREEN)
function setup()
tw={x=0,y=HEIGHT/2,rot=0}
tween(5,tw,{x=WIDTH,y=HEIGHT/2,rot=720},
{easing=tween.easing.linear,loop=tween.loop.pingpong})
end
function draw()
background(40, 40, 50)
translate(tw.x,tw.y)
rotate(tw.rot)
sprite("Cargo Bot:Clear Button")
end