Jump to content

Drag a sprite to move another sprite


AndersCan
 Share

Recommended Posts

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

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...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...