Hi,
When i use a class, my body with ES6 is different as you can see with debug mode activated. The body with es6 is smaller than the image. With the simple method, the body fit the image.
Could you tell me how to set my block correctly with ES6 to seems like the basic method ?
https://codepen.io/ogames/pen/LwRJJV
class Block extends Phaser.Physics.Matter.Sprite {
constructor(scene, x, y) {
super(scene.matter.world, x, y);
this.setTexture('block')
this.setPosition(x, y)
scene.add.existing(this)
}
preUpdate(time, delta) {
super.preUpdate(time, delta)
if (this.y > 600)
{
this.setPosition(50, 0);
this.setVelocity(0, -10);
}
}
}
var block_simple;
var block_with_es6
var game = new Phaser.Game(config);
function preload ()
{
this.load.image("block", "https://i.postimg.cc/KvY7DVGx/player.png");
this.load.image("platform", "https://i.postimg.cc/rp0KLGc5/platform.png");
this.load.image("particle","https://i.postimg.cc/wBkhzJCj/particle.png")
}
function create ()
{
block_simple = this.matter.add.image(400, 200,"block"); //here the body fit the image
block_with_es6 = new Block(this,50, 200);// here the body is small
var ground = this.matter.add.image(600, 600, 'platform', null, { isStatic: true });
ground.setScale(2, 0.5);
ground.setAngle(10);
ground.setFriction(0);
}
function update ()
{
}
var config = {
type: Phaser.CANVAS,
width: 800,
height: 800,
backgroundColor: '#0d1018',
physics: {
default: 'matter',
matter: {
debug: true,
},
},
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);