Skip to content

Instantly share code, notes, and snippets.

@corpsefilth
corpsefilth / tweenInfo.js
Last active August 29, 2015 14:15
Tween information. Phaser
// 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();
@corpsefilth
corpsefilth / audioInfo.js
Created February 21, 2015 02:04
Loading music assets. Phaser
// 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
@corpsefilth
corpsefilth / spriteInfo.js
Created February 16, 2015 08:08
Phaser Sprite reference
// 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)
@corpsefilth
corpsefilth / groupInfo.js
Created February 16, 2015 08:01
More info on Phaser groups
// 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();
@corpsefilth
corpsefilth / sampleState.js
Last active August 29, 2015 14:15
What is a state? Phaser State sample structure
// 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.