MouseInput.lua 597 B

123456789101112131415161718192021222324252627
  1. -- Mouse input example
  2. -- Set the image position to mouse position when the mouse is moved
  3. -- and change the image color when mouse is left or right clicked
  4. screen = Screen()
  5. image = ScreenImage("Resources/polycode_logo.png")
  6. image:setPositionMode(ScreenEntity.POSITION_CENTER)
  7. screen:addChild(image)
  8. function onMouseMove(x,y)
  9. image.position.x = x
  10. image.position.y = y
  11. end
  12. function onMouseDown(button, x,y)
  13. if button == 0 then
  14. image:setColor(1.0, 0.0, 0.0, 1.0)
  15. else
  16. image:setColor(0.0, 1.0, 0.0, 1.0)
  17. end
  18. end
  19. function onMouseUp(button, x,y)
  20. image:setColor(1.0, 1.0, 1.0, 1.0)
  21. end