sk-iv Posted February 21, 2016 Share Posted February 21, 2016 Hello, it is possible to drag sprite following (constraint) path? Link to comment Share on other sites More sharing options...
Zeterain Posted February 21, 2016 Share Posted February 21, 2016 Although there is no built-in way to follow a path that I'm aware of, you can use drag events to snap your sprite to a path as you drag it. (Drag events example: http://phaser.io/examples/v2/input/drag-update) Just calculate where along the path the sprite should be given the cursor position and update the sprite's position accordingly using the onDragUpdate event. Link to comment Share on other sites More sharing options...
sk-iv Posted February 21, 2016 Author Share Posted February 21, 2016 // This is the path var graphics = game.add.graphics(0, 0); graphics.lineStyle(10, 0xffd900, 1); graphics.moveTo(495,207); graphics.bezierCurveTo(470,178,434,160,393,160); graphics.bezierCurveTo(319,160,259,220,259,294); graphics.bezierCurveTo(259,368,319,428,393,428); graphics.bezierCurveTo(434,428,470,410,495,382); // This is the handler, which should move along handler = game.add.sprite(495,207, 'handler'); handler.anchor.setTo(0.5, 0.5); //Also enable sprite for drag handler.inputEnabled = true; handler.input.enableDrag(); handler.events.onDragUpdate.add(dragUpdate); Link to comment Share on other sites More sharing options...
sk-iv Posted February 21, 2016 Author Share Posted February 21, 2016 4 hours ago, Zeterain said: calculate where along the path the sprite should be given the cursor position how to calculate this? Link to comment Share on other sites More sharing options...
Recommended Posts