Advertisement
Guest User

Orbit around object, direction

a guest
Jun 25th, 2014
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. local function Main()
  2. local rect
  3. local radius = 20 --Orbit distance of "center"
  4. local angle = 90 --Starting angle
  5.  
  6. local orbitx = 125;
  7. local orbity = 125;
  8.  
  9. local direction = false; --True or false, postive or negative
  10. local function Orbit(event)
  11. rect.x = orbitx + math.cos(math.rad(angle)) * radius
  12. rect.y = orbity + math.sin(math.rad(angle)) * radius
  13. if(direction == false)then
  14. angle = angle + 3
  15. else
  16. angle = angle - 3;
  17. end
  18. end
  19.  
  20. rect = display.newRect(0,0,50,50)
  21. rect:setReferencePoint(display.BottomLeftReferencePoint)
  22. local prevX = nil;
  23. local prevY = nil;
  24. function rect:touch(event)
  25. local p = event.phase;
  26. if(p ~= nil)then
  27. if(p == "began")then
  28. prevX = event.x;
  29. prevY = event.y;
  30. elseif(p == "moved")then
  31. if(event.x > prevX and event.y > prevY)then
  32. direction = false;
  33. else
  34. direction = true;
  35. end
  36.  
  37. Orbit(event);
  38. end
  39. end
  40. end
  41. rect:addEventListener("touch", rect);
  42. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement