Jump to content

Add Camera offset to mouse pointer when dragging sprite


Schludi
 Share

Recommended Posts

Hello!

 

As-is Situation:

I have a world with more width than the game has, because the camera should follow a sprite that is draggable by mouse and can be thrown through the world.

 

https://phaser-schludi.c9.io/beer-througher/beerThrougher.1.html

 

My problem: 

When the camera follows the sprite, the game.input.mousePointer has not the offset of the camera, so that i cannot grab the sprite when it is on the right side.

function mouseDragStart() {    game.physics.box2d.mouseDragStart(game.input.mousePointer);    startX=Math.round(sprite.x);    startY=Math.round(sprite.y);    headline.text='Start Point: (' + startX + ','+ startY +')';}function mouseDragMove() {    game.physics.box2d.mouseDragMove(game.input.mousePointer);}

Question:

How can i add the offset to the mouse pointer that i can grab the sprite when it is on the right side?

 

Link to comment
Share on other sites

When i assign the mousePointers worldX to x it works... but i don't know if this is the solution?

function mouseDragMove() {    // When not adding this two lines, the camera offset is not dragged    // when the beer is on the right side    game.input.mousePointer.x=game.input.mousePointer.worldX;    game.input.mousePointer.y=game.input.mousePointer.worldY;    game.physics.box2d.mouseDragMove(game.input.mousePointer);}
Link to comment
Share on other sites

  • 1 month later...

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