Created
April 18, 2019 15:54
-
-
Save codebykeoma/d0425dfa6ef262f74c623af662b47992 to your computer and use it in GitHub Desktop.
This is my code for lesson number 5 in the player "Making your first Phaser 3 game" on phaser.io. I created this gist to show a student corrections for code he shared with me.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ZERO = 0; | |
const GAME_WIDTH = 800; | |
const GAME_HEIGHT = 600; | |
let config = { | |
type: Phaser.AUTO, | |
width: GAME_WIDTH, | |
height: GAME_HEIGHT, | |
physics: { | |
default: 'arcade', | |
arcade: { | |
gravity: { y: 300 }, | |
debug: false | |
} | |
}, | |
scene: { | |
preload: preload, | |
create: create, | |
update: update | |
} | |
}; | |
let 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 | |
} | |
); | |
} | |
function create() { | |
// this.add.image(GAME_WIDTH/2, GAME_HEIGHT/2, 'sky').setOrigin(0, 0) | |
this.add.image(GAME_WIDTH/2, GAME_HEIGHT/2, 'sky'); | |
let 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'); | |
let 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', | |
franes: [{ | |
key: 'dude', | |
frame: 4 | |
}], | |
frameRate: 20 | |
}); | |
this.anims.create({ | |
key: 'right', | |
frames: this.anims.generateFrameNumbers( | |
'dude', | |
{ | |
start: 5, | |
end: 8 | |
} | |
), | |
frameRate: 10, | |
repeat: -1 | |
}); | |
} | |
function update() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment