Mikkiz Posted October 9, 2017 Share Posted October 9, 2017 I'm trying to make a menu like option to where the user can drag a sprite on screen and make a clone out of it leaving the other sprite on it's original location. This is what I have up untill now. var box = game.add.sprite(100, 200, 'box', 0); box.anchor.set(0); box.inputEnabled = true; box.events.onInputDown.add(clone, this, 0, box); function clone(obj){ var clone = game.add.sprite(obj.x, obj.y, obj.key, obj.frame); clone.inputEnabled = true; clone.input.enableDrag(true); } Only down side is I have to click twice on the sprite in order for there to be a copy of it which kind of takes away the whole purpose of a copy on drag function. Any help would be greatly appreciated. (I'm quite new to Phaser and js so I'm sorry for any obvious mistakes beforehand) Thanks in advance! Link to comment Share on other sites More sharing options...
samid737 Posted October 10, 2017 Share Posted October 10, 2017 You could use startDrag(pointer) to make it work, but the the spawn point must be set to zero: var clone = game.add.sprite(0, 0, obj.key, obj.frame); clone.inputEnabled = true; clone.input.enableDrag(true); clone.input.startDrag(game.input.activePointer); An alternative is to trigger the event of hovering over the cloned object and then startDrag: var clone = game.add.sprite(obj.x, obj.y, obj.key, obj.frame); clone.inputEnabled = true; clone.input.enableDrag(true); clone.events.onInputOver.add(function(clone, pointer){ clone.input.startDrag(pointer); },this); Mikkiz 1 Link to comment Share on other sites More sharing options...
Mikkiz Posted October 10, 2017 Author Share Posted October 10, 2017 That is exactly what I needed thank you very much! samid737 1 Link to comment Share on other sites More sharing options...
Recommended Posts