Coganjen

Handle Dragging Sprite as Child of another Sprite

Recommended Posts

Hello all :)

I am pretty new to Phaser. Now I am testing to create drag and drop shape game.

I use this code :

var background = game.add.sprite(0,	0, 'atlas', 'background.png');
var shape = game.add.sprite(0, 0, 'atlas_test');
shape.frameName = 'ellipse.png' ;

shape.inputEnabled = true;
shape.input.enableDrag();

In short, this works fine, I drag with my mouse, and it follows my mouse pointer location. But problem happens when I add this :

background.addChild(shape);

When I add the draggable shape into background, somehow the draggable shape is several x and y away from the actual mouse pointer. Like, the shape is 'late'.

I wonder if the shape is following the background viewport since background is the parent.

44a9ff8bfde548ccbc53d81b08208bf9.png

Initially, my pointer on the center of this ellipse, then I drag to northeast, the shape follows the pointer but kind of late.

I wonder if is there any lead I can look upon, I need to persist shape as child of background, with normal drag as if the shape is not a of anyone's children.

 

Thank you.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.