In Arcade physics, I can create an object group like this:
scoreboardGroup = this.physics.add.group()
How can I do the same thing in Matter physics?
Thank you!
I’m probably newer than you to Phaser3 (I picked it up a month ago) but maybe take a look at this similar question from a year ago:
Thank you for your answer.
In my game, there are some kind of objectives that player can collide with, but each kind has a different event when it hits player.
What I could find is, all of collision events will be handled in this:
this.matter.world.on(‘collisionstart’, function (event) {
// code here
console.log("colision between " + pairs[0].bodyA.label + " - " + pairs[0].bodyB.label);
}
In my case I don’t know how to set label for the body of my objects.
How can I know which objects that collided?
Hi, can I ask how do you do this in Matter Physics? I’m trying to convert mine to Matter Physics and I’m having the same problem?
There are no physics groups for Matter Physics. You can use Matter sprites in regular groups, using group.add()
.
I have a function where I will need to keep generating the item from the top, but I couldn’t either get it shown or work?
Show your code and any errors you’re getting.
preload() {
this.load.image("background", "image/gotBg.png");
this.load.image("character", "image/tyrion.png");
this.load.image("dodge", "image/dagger.png");
this.load.image("collect", "image/cups.png");
this.load.atlas('buttons', './Assets/Sprites/btn_atlas.png','./Assets/Sprites/btn_atlas.json');
}
create() {
// buttons
this.btnLeft = this.add.existing(new GameButton(this,1604, 896, 'buttons', 'btnleft'));
this.btnRight = this.add.existing(new GameButton(this,1796, 896, 'buttons', 'btnright'));
this.btnLeft.onPressed =()=> {
this.player.setVelocityX(-5);
}
this.btnLeft.onReleased=()=> {
this.player.setVelocityX(0);
}
this.btnRight.onPressed =()=> {
this.player.setVelocityX(5);
}
this.btnRight.onReleased=()=> {
this.player.setVelocityX(0);
}
// background
this.platforms = this.add.tileSprite(208, 300, 416, 600, 'background');
this.player = this.matter.add.sprite(200, 520, 'character');
const item = this.add.group();
// genarate item
function generate() {
const xCoord = Math.random() * 450;
item.create(xCoord, 10, 'collect');
}
const generateLoop = this.time.addEvent({
delay: 2500,
callback: generate,
callbackScope: this,
loop: true
})
}
it is looping now but the item is not dropping down
Change to
item.add(this.matter.add.sprite(xCoord, 10, 'collect'));
It is still the same…