Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function Main()
- local rect
- local radius = 20 --Orbit distance of "center"
- local angle = 90 --Starting angle
- local orbitx = 125;
- local orbity = 125;
- local direction = false; --True or false, postive or negative
- local function Orbit(event)
- rect.x = orbitx + math.cos(math.rad(angle)) * radius
- rect.y = orbity + math.sin(math.rad(angle)) * radius
- if(direction == false)then
- angle = angle + 3
- else
- angle = angle - 3;
- end
- end
- rect = display.newRect(0,0,50,50)
- rect:setReferencePoint(display.BottomLeftReferencePoint)
- local prevX = nil;
- local prevY = nil;
- function rect:touch(event)
- local p = event.phase;
- if(p ~= nil)then
- if(p == "began")then
- prevX = event.x;
- prevY = event.y;
- elseif(p == "moved")then
- if(event.x > prevX and event.y > prevY)then
- direction = false;
- else
- direction = true;
- end
- Orbit(event);
- end
- end
- end
- rect:addEventListener("touch", rect);
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement