Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//Handle dragging from within a scaled parent
//Currently just drags from center of sprite
function scaledDrag(sprite) {
sprite.inputEnabled = true;
sprite.input.enableDrag();
sprite.events.onDragUpdate.add(function (sprite, pointer, x, y) {
var pos = sprite.game.input.getLocalPosition(sprite.parent, pointer);
if (sprite.hitArea) {
sprite.x = pos.x - sprite.hitArea.width/2;
sprite.y = pos.y - sprite.hitArea.height/2;
} else {
sprite.x = pos.x - sprite.width/2;
sprite.y = pos.y - sprite.height/2;
}
}, sprite);
return sprite;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.