2
0

MouseInput.lua 705 B

1234567891011121314151617181920212223242526272829
  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. scene = Scene(Scene.SCENE_2D)
  5. scene:getActiveCamera():setOrthoSize(640,480)
  6. image = SceneImage("Resources/polycode_logo.png")
  7. scene:addChild(image)
  8. function onMouseMove(x,y)
  9. local ray =scene:projectRayFromCameraAndViewportCoordinate(scene:getActiveCamera(), Vector2(x,y))
  10. image:setPosition(ray.origin.x, ray.origin.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