Skip to content

Instantly share code, notes, and snippets.

View ekelokorpi's full-sized avatar

Eemeli Kelokorpi ekelokorpi

View GitHub Profile
@ekelokorpi
ekelokorpi / main.js
Created October 24, 2014 11:39
Audio: Pause
// Play sound
var jumpSound = game.audio.playSound('jump');
// Pause sound
game.audio.pauseSound(jumpSound);
// Resume sound
game.audio.resumeSound(jumpSound);
// Pause all playing sounds
@ekelokorpi
ekelokorpi / main.js
Created October 24, 2014 11:38
Audio: Basic usage
// Add audio to load queue and give it id 'jump'
game.addAudio('jump.m4a', 'jump');
// Play sound
var jumpSound = game.audio.playSound('jump');
// Stop sound
game.audio.stopSound(jumpSound);
@ekelokorpi
ekelokorpi / main.js
Created October 24, 2014 11:35
Animation: Basic usage
// Create animation with 3 frames
var anim = new game.Animation('frame1.png', 'frame2.png', 'frame3.png');
// Set animation speed
anim.animationSpeed = 0.2;
// Play animation
anim.play();
// Add animation to stage
anim.addTo(game.scene.stage);
@ekelokorpi
ekelokorpi / main.js
Created October 24, 2014 10:51
TilingSprite: Speed
var sprite = new game.TilingSprite('sprite.png', 1000, 1000);
// Set speed for TilingSprite
sprite.speed.set(50, 100);
sprite.addTo(game.scene.stage);
// Use addObject method, so TilingSprite will get updated
game.scene.addObject(sprite);
@ekelokorpi
ekelokorpi / main.js
Last active August 29, 2015 14:08
TilingSprite: Basic usage
// Create TilingSprite with size of 1000x1000
var sprite = new game.TilingSprite('sprite.png', 1000, 1000);
sprite.addTo(game.scene.stage);
@ekelokorpi
ekelokorpi / main.js
Created October 24, 2014 10:37
BitmapText: Change text
var text = new game.BitmapText('Hello', { font: 'MyFont' });
text.setText('New text');
@ekelokorpi
ekelokorpi / main.js
Created October 24, 2014 10:36
BitmapText: Basic usage
var text = new game.BitmapText('Hello', { font: 'MyFont' });
text.position.set(100, 100);
text.addTo(this.stage);
@ekelokorpi
ekelokorpi / main.js
Last active August 29, 2015 14:08
SpriteSheet: Basic usage
// Creates spritesheet with frame size 138x100
var spritesheet = new game.SpriteSheet('spritesheet.png', 138, 100);
// Returns sprite using frame 0 from spritesheet
var sprite = spritesheet.frame(0);
sprite.addTo(this.stage);
// Returns 15 frames long animation, starting from frame 2
var anim = spritesheet.anim(15, 2);
anim.animationSpeed = 0.3;
@ekelokorpi
ekelokorpi / main.js
Created October 23, 2014 16:34
Physics: Basic usage
// Create physics world
this.world = new game.World();
// Create new body
var body = new game.Body();
// Set body position
body.position.x = 200;
body.position.y = 200;
@ekelokorpi
ekelokorpi / main.js
Created October 19, 2014 16:11
Particle: Bitmap text
var text = new game.BitmapText('HELLO', { font: 'MyFont' });
text.cacheAsBitmap = true;
var emitter = new game.Emitter();
// Use cached sprite from BitmapText as particle texture
emitter.textures.push(text._cachedSprite.texture);