Aquarius

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 ?

 

 

EDIT : 

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;
        }
    }

 

 

Share this post


Link to post
Share on other sites

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

  • Recently Browsing   0 members

    No registered users viewing this page.