hi,
I made a minimal snippet to show what i want. If the enemy(red) touch the player(green) the player don’t collide with the enemy and the enemy fall to the bounds of the game.
my problem is that the enemy fall outside the game…why ?
https://jsfiddle.net/espace3d/j4qv1f0c/28/
var cat1;
var cat2;
var cat0;
var player;
var enemy;
config = {
type: Phaser.CANVAS,
width: 400,
height: 400,
backgroundColor: '#0d1018',
physics: {
default: 'matter',
matter: {
debug: true,
gravity: {
y: 1
},
}
},
callbacks: {
postBoot: function (game) {
//game.canvas.style.width = '100%';
//game.canvas.style.height = '100%';
}
},
scene: {
preload: preload,
create: create,
update: update,
}
};
var game = new Phaser.Game(config);
function preload() {
this.load.image("player", "https://i.postimg.cc/KvY7DVGx/player.png");
this.load.image("enemy", "https://i.postimg.cc/qRk6Mhg4/enemy.png");
}
function create() {
cat0 = this.matter.world.nextCategory();
cat1 = this.matter.world.nextCategory();
cat2 = this.matter.world.nextCategory();
this.matter.world.setBounds()
// player is green
player = this.matter.add.image(200, 300, 'player');
//enemy is red
enemy = this.matter.add.image(200, 100, 'enemy');
//collision category
enemy.setCollisionCategory(cat1);
player.setCollisionCategory(cat2);
enemy.setCollidesWith([cat2]);
this.matter.world.on('collisionstart', function (event) {
if (event.pairs[0].bodyB.gameObject.texture.key == "enemy") {
if (event.pairs[0].bodyA.gameObject.texture.key == "player") {
console.log('player is hit')
event.pairs[0].bodyA.gameObject.alpha =.1
//HERE MY PROBLEM i want that the player collide with nothing so the enemy normaly pass trough but can't go outside the screen and that 's the problem'
event.pairs[0].bodyA.gameObject.setCollidesWith([cat0])
}
}
})
}
function update() {
}
thanks.