AndersCan Posted June 6, 2015 Share Posted June 6, 2015 Hi,I'm new to Phaser and have had no luck with looking at the documentation to solve my problem. I'm creating a mobile game that will use touch(dragging) to move the player sprite. I want the user to able to actually see the player when moving it, so I want to add a sprite for the sole purpose of controlling the player sprite. The player sprite can only move left or right. This is the code I have created so far, but it doesn't do what I want it to do var controller = game.add.sprite(0, 0, cbox); game.physics.enable(controller, Phaser.Physics.ARCADE); controller.inputEnabled = true; controller.input.enableDrag(true); controller.input.allowHorizontalDrag = true; controller.input.allowVerticalDrag = false; controller.body.immovable = true; controller.body.moves = false; controller.events.onDragStart.add(doSomething, this);The first problem is that the Controller sprite is moving when I drag it. The Second problem is that the location of the Player sprite is only moved to the location where I started dragging. It only moves to the click events. Any ideas? Link to comment Share on other sites More sharing options...
AndersCan Posted June 6, 2015 Author Share Posted June 6, 2015 Figured it out! Need to override the updateDrag function.controller.input.updateDrag = function(pointer) { bouncer.x = pointer.x; // call the generic implementation: Phaser.InputHandler.prototype.updateDrag.call(this,pointer);} Link to comment Share on other sites More sharing options...
endel Posted June 6, 2015 Share Posted June 6, 2015 There is a "draggable" pixi.js plugin here: https://github.com/SebastianNette/PIXI.draggable It cannot be easily integrated with Phaser (AFAIK), but you can use it's source-code as a reference. Link to comment Share on other sites More sharing options...
Recommended Posts