Problem with rotating a sprite... - Gideros Forum

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Problem with rotating a sprite...

Member
edited March 2015
Hi,

I want to rotate a sprite by 90° each time, the screen is pressed. The rotation should be slow, so that you can see the circle rotating. And you should be allowed to tap certain times fast and the circle rotates the tapped times and stops. I already got working code, but there are some problems: I don't want to exeed 360° so, there must be a way to set the angle of the circle to 0° (360°), without corrupting the rotating.

Any ideas?

Here's my code:

circle = Bitmap.new(Texture.new("colorCircle_vhres.png"))

local function initGame()
y = 1100
x = 360
turns = 0
ang = 0
circle:setScale(0.3, 0.3)
circle:setAnchorPoint(0.5, 0.5)
circle:setX(x)
circle:setY(y)
circle:setRotation(0)
end

local function updateCircle()
if circle:getRotation() ~= turns * 90 then
circle:setRotation(ang)
ang = ang + 6
end
end

local function imagetouch(event)
local x = event.touch.x
local y = event.touch.y
turns = turns + 1
print("circ angle: " .. circle:getRotation())
print("Turns: " .. turns)
end

function updateGame(event)
end

initGame()