Skip to content

Instantly share code, notes, and snippets.

@gfxblit
Created August 14, 2021 03:59
Show Gist options
  • Save gfxblit/c2cafa5e07dcb873f8b5c1b1bc97da13 to your computer and use it in GitHub Desktop.
Save gfxblit/c2cafa5e07dcb873f8b5c1b1bc97da13 to your computer and use it in GitHub Desktop.
function create() {
this.add.image(400, 300, 'sky');
var platforms = this.physics.add.staticGroup();
platforms
.create(400, 568, 'ground')
.setScale(2)
.refreshBody();
platforms.create(600, 400, 'ground');
platforms.create(50, 250, 'ground');
platforms.create(750, 220, 'ground');
player = this.physics.add.sprite(100, 450, 'dude');
player.setBounce(0.2);
player.setCollideWorldBounds(true);
this.anims.create({
key: 'left',
frames: this.anims.generateFrameNumbers('dude', { start: 0, end: 3 }),
frameRate: 10,
repeat: -1,
});
this.anims.create({
key: 'turn',
frames: [{ key: 'dude', frame: 4 }],
frameRate: 20,
});
this.anims.create({
key: 'right',
frames: this.anims.generateFrameNumbers('dude', { start: 5, end: 8 }),
frameRate: 10,
repeat: -1,
});
this.physics.add.collider(player, platforms);
// Add this line of code below
cursors = this.input.keyboard.createCursorKeys();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment