2
0

KeyboardInput.lua 615 B

1234567891011121314151617181920212223242526272829
  1. -- Keyboard input example.
  2. -- Rotate the Polycode logo with left and right keys
  3. screen = Screen()
  4. image = ScreenImage("Resources/polycode_logo.png")
  5. image:setPositionMode(ScreenEntity.POSITION_CENTER)
  6. image:setPosition(640/2,480/2)
  7. screen:addChild(image)
  8. rotationSpeed = 0
  9. function onKeyDown(key)
  10. if key == KEY_LEFT then
  11. rotationSpeed = -200
  12. elseif key == KEY_RIGHT then
  13. rotationSpeed = 200
  14. end
  15. end
  16. function onKeyUp(key)
  17. if key == KEY_LEFT or key == KEY_RIGHT then
  18. rotationSpeed = 0
  19. end
  20. end
  21. function Update(elapsed)
  22. image.rotation.roll = image.rotation.roll + (elapsed * rotationSpeed)
  23. end