Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Problem with rotating a sprite... — Gideros Forum

Problem with rotating a sprite...

lhackmlhackm Member
edited March 2015 in General questions
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)
stage:addChild(circle)
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()
stage:addEventListener(Event.ENTER_FRAME, updateGame)
stage:addEventListener(Event.ENTER_FRAME, updateCircle)
stage:addEventListener(Event.TOUCHES_BEGIN, imagetouch)

Comments

Sign In or Register to comment.