I experimented with modifying the “First Game” code.
Look at the gravity of 1800.
var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
physics: {
default: 'arcade',
arcade: {
gravity: { y: 1800 },
debug: false
}
},
scene: {
preload: preload,
create: create,
update: update
}
};
Created objects.
platforms.create(400, 568, 'ground').setScale(2).refreshBody();
player = this.physics.add.sprite(100, 450, 'dude');
player.setBounce(0);
player.setCollideWorldBounds(true);
Collider settings
this.physics.add.collider(player, platforms);
this.physics.add.collider(stars, platforms);
this.physics.add.collider(player, stars);
result
Collision with the star works but the character passes through the ground.
Q: How can I prevent my character from crossing the ground?