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
// Create a tween on the label | |
var tween = game.add.tween(nameLabel); | |
// Change the y position of the label to 80, in 1000 ms | |
tween.to({y: 80}, 1000); | |
// Start the tween | |
tween.start(); | |
game.add.tween(nameLabel).to({y: 80}, 1000).start(); | |
game.add.tween(nameLabel).to({y: 80}, 1000).easing(Phaser.Easing.Bounce.Out).start(); |
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
// Load the music in 2 different formats, in the preload function | |
game.load.audio('music', ['assets/music.ogg', 'assets/music.mp3']); | |
// Add and start the music in the 'create' function | |
// Because we want to play the music when the play state starts | |
this.music = game.add.audio('music'); // Add the music | |
this.music.loop = true; // Make it loop | |
this.music.play(); // Start the music | |
// And don't forget to stop the music in the 'playerDie' function |
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
// Create a local variable | |
var someSprite = game.add.sprite(250, 170, 'someSprite'); | |
// Create a state variable | |
this.someSprite = game.add.sprite(250, 170, 'someSprite'); | |
// using predefined pos | |
this.someSprite = game.add.sprite(game.world.centerX, game.world.centerY, 'someSprite'); | |
// Set the anchor point to the top left of the sprite (default value) |
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
// A group can act like a giant sprite, so it has the same properties you can edit | |
group.x; | |
group.y; | |
group.alpha; | |
group.angle; | |
// Return the number of living members in the group | |
group.countLiving(); |
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
// Create one state called 'sampleState' | |
var sampleState = { | |
// Define all the functions of the state | |
preload: function() { | |
// This function will be executed at the beginning | |
// That's where we load the game's assets | |
}, | |
create: function() { | |
// This function is called after the preload function | |
// Here we set up the game, display sprites, etc. |
NewerOlder