Jump to content

Attach sprite to mouse


Punknoodles
 Share

Recommended Posts

I have a world larger than the screen and am trying to add a custom cursor. However, the cursor seems to move relative to the world, so I tried using fixedToCamera = true, but then it didn't move at all. Here's the relevant code:

 

// create event

customcursor = game.add.sprite(game.input.mousePointer.x, game.input.mousePointer.y, 'cursor');
customcursor.scale.setTo(0.5, 0.5);
customcursor.anchor.setTo(0.5, 0.5);
customcursor.fixedToCamera = true;

// update event

customcursor.x = game.input.mousePointer.x;

customcursor.y = game.input.mousePointer.y;

 

If anyone knows what's wrong with this, please tell me!

Link to comment
Share on other sites

You could set fixedToCamera to false, and just set your 'customcursor'  position to the input's world position by using 'game.input.worldX' and game.input.worldY'. This way you don't need to worry about taking any camera offsets into account because the world position of input already does that for you.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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