SHOW:
|
|
- or go back to the newest paste.
| 1 | - | local function Main() |
| 1 | + | local wheel = display.newGroup() |
| 2 | - | local rect |
| 2 | + | wheel.x, wheel.y = display.contentCenterX, display.contentCenterY |
| 3 | - | local radius = 20 --Orbit distance of "center" |
| 3 | + | |
| 4 | - | local angle = 90 --Starting angle |
| 4 | + | display.newRect(wheel, 50, 0, 10, 10) |
| 5 | ||
| 6 | - | local orbitx = 125; |
| 6 | + | display.newCircle(wheel, 0, 0, 5) |
| 7 | - | local orbity = 125; |
| 7 | + | |
| 8 | function wheel:touch(event) | |
| 9 | - | local direction = false; --True or false, postive or negative |
| 9 | + | local x, y = self:contentToLocal(event.x, event.y) |
| 10 | - | local function Orbit(event) |
| 10 | + | if event.phase == 'moved' then |
| 11 | - | rect.x = orbitx + math.cos(math.rad(angle)) * radius |
| 11 | + | self.rotation = self.rotation + math.deg(math.atan2(y, x)) |
| 12 | - | rect.y = orbity + math.sin(math.rad(angle)) * radius |
| 12 | + | for i= 1, self.numChildren do |
| 13 | - | if(direction == false)then |
| 13 | + | self[i].rotation = -self.rotation |
| 14 | - | angle = angle + 3 |
| 14 | + | end |
| 15 | - | else |
| 15 | + | end |
| 16 | - | angle = angle - 3; |
| 16 | + | end |
| 17 | - | end |
| 17 | + | |
| 18 | - | end |
| 18 | + | Runtime:addEventListener('touch', wheel) |