Hi!
I've just started working with the Starling Framework and was stuck when I had to move an object according to the mouse position. For right now I'm developing a game for desktop (not for mobile devices with touch screen) and I need to make an object follow the mouse. In the book "Introducing Starling" I found that there is something like a mouse move event but it dispatches only if the mouse is down. So is it possible to get mouse position at any time or is there any analogue to native MOUSE_MOVE event?
Thanks.
Mouse move event or is it possible to get mouseX and mouseY at any time?
(4 posts) (2 voices)-
Posted 1 year ago #
-
I think you will find what you are looking for here :
http://forum.starling-framework.org/topic/how-listenmouse-eventmouse_down-with-starlingAnd the phase you would use is phase.HOVER and you would get the mouse coords like this :
e.getTouch(yourObject).globalX e.getTouch(yourObject).globalY
With "e" being your event object.
I used it for a paralax effect and it worked well.
Posted 1 year ago # -
Thanks a lot) I managed to make my object follow the mouse.
I wrote this code inside of the root starling class:
private function onMove(event:TouchEvent):void { var touch:Touch = event.getTouch(this); if(touch.phase == TouchPhase.HOVER) { testMc.x = touch.globalX; testMc.y = touch.globalY; } } private function onAdded ( event:Event ):void { //TouchEvent is dispatched only if the mouse covers any object on the starling stage q = new Quad(stage.stageWidth, stage.stageHeight); q.setVertexColor(0, 0x000000); q.setVertexColor(1, 0xAA0000); q.setVertexColor(2, 0x00FF00); q.setVertexColor(3, 0x0000FF); addChild ( q ); testMc = new MovieClip(txCache,24); addChild(testMc); Starling.juggler.add(testMc); testMc.x = stage.stageWidth/2; testMc.y = stage.stageHeight/2; addEventListener(TouchEvent.TOUCH, renderGame); }
but it only works if the root Class object entirely covers the stage
Posted 1 year ago # -
Cool! Great to see you got it to work.
I think you could also add the listener to the starling stage.
Posted 1 year ago #
Reply
You must log in to post.