Jump to content

How to get absolute coordinates of a click pointer on a tilesprite?


weratius
 Share

Recommended Posts

Hello, guys!

I have a tilesprite on a background:

function createSpace() {

    var space = game.add.tileSprite(0, 0, game.width, game.height, 'space');
    space.fixedToCamera = true;
    space.inputEnabled = true;
    space.events.onInputDown.add(this.goToPointer);
    layers.backgroundLayer.add(space);

    return space;
}

 

spaceSystem.prototype.update = function() {

    //here I move a tilesprite when I user arrows
    if(this.space != null) {
        this.space.tilePosition.set(game.camera.x * -0.5, game.camera.y * -0.5);
    }
}

 

Because this method returns my screen coordinates:

var myObject = this;

spaceSystem.prototype.goToPointer = function() {

    var x = game.math.snapToFloor(game.input.x, 6080) / 6080;
    var y = game.math.snapToFloor(game.input.y, 6080) / 6080;

    myObject.myShip.ship.x = x;
    myObject.myShip.ship.y = y;

    console.log(x, y); //1071, 801
}

But it must be 3000 and 2000 for example

The width and the height of my tilesprite = 6080

I have a question: how can I get the absolute coordinates of a click pointer on a tilesprite?

Thank you in advance

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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