I have a sprite controlled by the player with CursorKeys (top, bottom, left, right)
I integrated a collision without physics between my sprite and a zone with Phaser.Geom.Intersects.LineToRectangle() because I am testing each side of my sprite for collision.
It works fine, but if the right bound of my sprite collides with the zone, I can’t move my sprite up and down because the last point of the bound up and bound down also collides with the zone…
How can I do ?
sample here :
function() update {
[...]
let leftBound = sprite.getBounds().getLineD();
let rightBound = sprite.getBounds().getLineB();
let upBound = sprite.getBounds().getLineA();
let downBound = sprite.getBounds().getLineC();
let leftIntersect = Phaser.Geom.Intersects.LineToRectangle(leftBound,this.zone.getBounds());
let rightIntersect = Phaser.Geom.Intersects.LineToRectangle(rightBound,this.zone.getBounds());
let upIntersect = Phaser.Geom.Intersects.LineToRectangle(upBound,this.zone.getBounds());
let downIntersect = Phaser.Geom.Intersects.LineToRectangle(downBound,this.zone.getBounds());
if (cursors.left.isDown && leftIntersect == false) {
sprite.x -= SPEED;
sprite.anims.play('walk',true);
} else if (cursors.right.isDown && rightIntersect == false) {
sprite.x += SPEED;
sprite.anims.play('walk',true);
} else if (cursors.up.isDown && upIntersect == false) {
sprite.y += -SPEED;
sprite.anims.play('walk',true);
} else if(cursors.down.isDown && downIntersect == false) {
sprite.y += SPEED;
sprite.anims.play('walk',true);
} else {
sprite.anims.play('idle');
}
}