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. scene = Scene(Scene.SCENE_2D)
  7. sun = ScenePrimitive(ScenePrimitive.TYPE_CIRCLE, 0.2,0.2, 30)
  8. sun:setColor(0.9, 0.8, 0, 1)
  9. sun.colorAffectsChildren = false
  10. scene:addChild(sun)
  11. planet = ScenePrimitive(ScenePrimitive.TYPE_CIRCLE, 0.1,0.1, 30)
  12. planet:setPosition(0.3,0)
  13. planet:setColor(0.2, 0.8, 0, 1)
  14. planet.colorAffectsChildren = false
  15. sun:addChild(planet)
  16. moon = ScenePrimitive(ScenePrimitive.TYPE_CIRCLE, 0.05, 0.05, 30)
  17. moon:setPosition(0.1,0)
  18. moon:setColor(1, 1, 0.6, 1)
  19. planet:addChild(moon)
  20. planetRotation = 0
  21. moonRotation = 0
  22. function Update(elapsed)
  23. planetRotation = planetRotation + elapsed
  24. moonRotation = moonRotation + (elapsed * 6)
  25. planet:setPosition(cos(planetRotation)*0.3, sin(planetRotation)*0.3)
  26. moon:setPosition(cos(moonRotation)*0.1, sin(moonRotation)*0.1)
  27. end