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

  • Recently Browsing   0 members

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