I was able to use .onFloor() in arcade, but I’m not sure how to do it in matter.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Making your first Phaser 3 Game - Part 10</title>
<script src="//cdn.jsdelivr.net/npm/phaser@3.55.2/dist/phaser.js"></script>
<style type="text/css">
body {
margin: 0;
background-color: black;
}
canvas {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="game"></div>
<script type="text/javascript">
const config = {
type: Phaser.AUTO,
backgroundColor: "#48C4F8",
width: 960,
height: 540,
pixelArt: true,
scale: {
parent: 'game',
autoCenter: Phaser.Scale.CENTER_BOTH
},
physics: {
default: 'matter',
matter: {
gravity: { y: 2 },
debug: false
}
},
scene: {
preload: preload,
create: create,
update: update
}
};
var game = new Phaser.Game(config);
function preload() {
this.load.image('sky', 'assets/sky.png');
this.load.image('ground', 'assets/platform.png');
this.load.image('star', 'assets/star.png');
this.load.image('bomb', 'assets/bomb.png');
this.load.spritesheet('dude',
'assets/dude.png',
{ frameWidth: 32, frameHeight: 48 }
);
this.load.image('spike', 'assets/images/spike.png');
// At last image must be loaded with its JSON
this.load.atlas('player', 'assets/images/kenney_player.png', 'assets/images/kenney_player_atlas.json');
this.load.image('tiles', 'assets/tilesets/platformPack_tilesheet.png');
// Load the export Tiled JSON
this.load.tilemapTiledJSON('map', 'assets/tilemaps/level1.json');
}
function create() {
background = this.add.image(512, 310, 'sky');
player = this.matter.add.sprite(40, 0, "player", 4);
this.anims.create({
key: 'walk',
frames: this.anims.generateFrameNames('player', {
prefix: 'robo_player_',
start: 2,
end: 3,
}),
frameRate: 10,
repeat: -1
});
this.anims.create({
key: 'idle',
frames: [{
key: 'player',
frame: 'robo_player_0'
}],
frameRate: 10,
});
this.anims.create({
key: 'jump',
frames: [{
key: 'player',
frame: 'robo_player_1'
}],
frameRate: 10,
});
this.cursors = this.input.keyboard.createCursorKeys();
const map = this.make.tilemap({
key: 'map'
});
const tileset = map.addTilesetImage('kenny_simple_platformer', 'tiles');
const platforms = map.createStaticLayer('Platforms', tileset, 0, 0);
platforms.setCollisionByProperty({ collides: true });
this.matter.world.convertTilemapLayer(platforms);
platforms.setCollisionByExclusion(-1, true);
platforms.setCollisionByProperty({ collides: true });
this.matter.world.convertTilemapLayer(platforms);
this.matter.add.gameObject(player);
this.matter.world.on("collisionactive", (player, platforms) => {
skaterTouchingGround = true;
});
}
function update() {
if (this.cursors.left.isDown) {
player.setVelocityX(-3);
player.play('walk', true);
} else if (this.cursors.right.isDown) {
player.setVelocityX(3);
player.play('walk', true);
}
if ((this.cursors.space.isDown || this.cursors.up.isDown) && skaterTouchingGround) {
skaterTouchingGround = false;
player.setVelocityY(-3);
player.play('jump', true);
}
}
</script>
</body>
type or paste code here