Jump to content

Phaser, is Cursor in collide area ?


Recommended Posts

Hi everyone,

I am using arcade physics and my collisions are definer by a Tiled layer.

        this.collisionLayer = collisionLayer;
        this.map.setCollisionByExclusion([], truethis.collisionLayer);

I have a sprite attached to my cursor, but it seems that (in update)

        if (this.phaserGame.physics.arcade.collide(this.marker, this.collisionLayer)) {
            console.log('hey, cursor is over collide area !!');

won't work because Phaser check if a Sprite is gonna collide, not if it's actually colliding.


What I simply need is to know if my marker (or directly my input.activePointer) is colliding.

Any clues ?




Actually :

when updating marker position, I get the tile below my cursor.

If there is a tile AND his property 'canCollide' is set to true, I did not update marker position.

    private setMarker() {
        let marker: Phaser.Sprite = this.marker,
            tilePointBelowPointer: Phaser.Point = this.pointToTilePosition(); // get tile coordinate below activePointer
        let tileBelowPointer: Phaser.Tile = this.map.getTileWorldXY(tilePointBelowPointer.x, tilePointBelowPointer.y, 1616this.collisionLayer);
        if (tileBelowPointer && tileBelowPointer.canCollide) {
            // do something if you want
        } else {
            marker.x = tilePointBelowPointer.x;
            marker.y = tilePointBelowPointer.y;



Link to comment
Share on other sites


  • Recently Browsing   0 members

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