2
0

ScreenEntities.lua 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. --
  2. -- This example demonstrates entity hierarchy by simulating a simple solar system.
  3. -- Since entity transformations are always relative to the entity's parent
  4. -- so the moon's rotation takes places around the planet, which is its parent.
  5. --
  6. screen = Screen()
  7. sun = ScreenShape(ScreenShape.SHAPE_CIRCLE, 100,100, 30)
  8. sun:setPosition(640/2, 480/2)
  9. sun:setColor(0.7, 0.5, 0.3, 1)
  10. sun.colorAffectsChildren = false
  11. screen:addChild(sun)
  12. planet = ScreenShape(ScreenShape.SHAPE_CIRCLE, 50,50, 30)
  13. planet:setPosition(150,0)
  14. planet:setColor(0.2, 0.8, 0, 1)
  15. planet.colorAffectsChildren = false
  16. sun:addChild(planet)
  17. moon = ScreenShape(ScreenShape.SHAPE_CIRCLE, 20,20, 30)
  18. moon:setPosition(50,0)
  19. moon:setColor(1, 1, 0.6, 1)
  20. planet:addChild(moon)
  21. planetRotation = 0
  22. moonRotation = 0
  23. function Update(elapsed)
  24. planetRotation = planetRotation + elapsed
  25. moonRotation = moonRotation + (elapsed * 6)
  26. planet:setPosition(cos(planetRotation)*150, sin(planetRotation)*150)
  27. moon:setPosition(cos(moonRotation)*50, sin(moonRotation)*50)
  28. end