2
0

KeyboardInput.lua 556 B

12345678910111213141516171819202122232425262728
  1. -- Keyboard input example.
  2. -- Rotate the Polycode logo with left and right keys
  3. scene = Scene(Scene.SCENE_2D)
  4. scene:getDefaultCamera():setOrthoSize(640, 480)
  5. image = SceneImage("Resources/polycode_logo.png")
  6. scene:addChild(image)
  7. rotationSpeed = 0
  8. function onKeyDown(key)
  9. if key == KEY_LEFT then
  10. rotationSpeed = 200
  11. elseif key == KEY_RIGHT then
  12. rotationSpeed = -200
  13. end
  14. end
  15. function onKeyUp(key)
  16. if key == KEY_LEFT or key == KEY_RIGHT then
  17. rotationSpeed = 0
  18. end
  19. end
  20. function Update(elapsed)
  21. image:Roll(elapsed * rotationSpeed)
  22. end