alestane icon

Rotating wheel

alestane | PRO | 06/25/14 07:51:16 PM UTC | 0 ⭐ | 494 👁️ | Never ⏰ | []
Lua |

480 B

|

None

|

0 👍

/

0 👎

local wheel = display.newGroup()
wheel.x, wheel.y = display.contentCenterX, display.contentCenterY
 
display.newRect(wheel, 50, 0, 10, 10)
 
display.newCircle(wheel, 0, 0, 5)
 
function wheel:touch(event)
    local x, y = self:contentToLocal(event.x, event.y)
    if event.phase == 'moved' then
        self.rotation = self.rotation + math.deg(math.atan2(y, x))
        for i= 1, self.numChildren do
            self[i].rotation = -self.rotation
        end
    end
end
 
Runtime:addEventListener('touch', wheel)

Comments