Reputation: 87
I have been following the intro to phaser 3 here http://phaser.io/tutorials/making-your-first-phaser-3-game and have found my character 'hovering' above the platforms that I have made.
The rest of this post can be ignored if either of these questions can be answered:
Is there a padding property given to sprites and can it be removed?
can sprites be given collision mask dimensions?
Here is my code initializing the player and the platforms as well as the collision code.
(I realize defining the player on 'this' may be an odd way of doing things)
clouds = this.physics.add.staticGroup();
platforms = this.physics.add.staticGroup();
platforms.create(0, 400, 'platform').setScale(0.5).refreshBody();
clouds.create(200, 410, 'plc-cloud').setScale(0.5).refreshBody();
//player
this.player = this.physics.add.sprite(0,300,'player').setScale(0.5);
this.player.speed = 5.5;
this.player.isMoving = false;
this.player.isCrouching = false;
this.player.setCollideWorldBounds(true);
this.player.body.setGravityY(400);
this.physics.add.collider(this.player, platforms);
this.physics.add.collider(this.player, clouds);
The image dimensions: player: 100x100 pix clouds: 150x150 platforms: 400x32
This is the result platform hover
Upvotes: 0
Views: 84
Reputation: 1122
Your sprite shouldn't be given a padding property unless you're specifying something other than 0 for the margin or spacing when you're loading the sprite.
You can set the sprite's collision dimensions with setSize(width, height)
See the Phaser docs here.
If you turn on debug in your physics config, it should draw the boxes around the platform and your sprite so you can determine the appropriate dimensions. Something like:
physics: {
default: 'arcade',
arcade: {
debug: true
}
}
Upvotes: 1