Skip to content

Instantly share code, notes, and snippets.

var isColliding, scrollSprite, playerSprite, scrollSpeedX;
create: function() {
isColliding = false;
canScroll = true;
scrollSpeedX = 10;
},
update: function() {
if(!isColliding) {
scrollSprite.tilePosition.x -= scrollSpeedX;
@ada-lovecraft
ada-lovecraft / gist:10882949
Last active August 29, 2015 13:59
Phaser: Set mass of particles:
var emitter = game.add.emitter(x, y, numParticles);
emitter.enableBody = true;
emitter.makeParticles('key');
// try this first
emitter.setAll('body.mass', 0);
// if that doesn't work
emitter.forEach(function(particle) {
particle.body.mass = 0;
@ada-lovecraft
ada-lovecraft / gist:819dc5e2fd794b032a8a
Created July 10, 2014 15:27
create a simple timer in phaser
var duration = 1000;
var context = this;
var timer = game.time.create();
timer.add(duration, firstTimerEventCallback, context);
timer.add(duration * 2, secondTimerEventCallback, context);
timer.onComplete.add(timerCompleted, context);
timer.start();
@ada-lovecraft
ada-lovecraft / Rope.js
Created July 15, 2014 16:30
phaser.rope
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2014 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* A Rope is a Sprite that has a repeating texture. The texture can be scrolled and scaled and will automatically wrap on the edges as it does so.
* Please note that Ropes, as with normal Sprites, have no input handler or physics bodies by default. Both need enabling.
*
@ada-lovecraft
ada-lovecraft / demo.js
Created July 15, 2014 16:59
phaser-rope-setup
var game = new Phaser.Game(window.innerWidth, window.innerHeight, Phaser.AUTO, '',{preload: preload, create: create, update:update});
var rope;
function preload() {
console.log('preload');
game.load.image('snake', 'assets/snake.png');
}
function create() {
@ada-lovecraft
ada-lovecraft / play.js
Created July 31, 2014 17:38
Balls and things
'use strict';
var TouchCircle = require('../prefabs/TouchCircle');
var Circle = require('../prefabs/Circle');
function Play() {
this.bullets = null;
this.angle = null;
this.cannon = null;
@ada-lovecraft
ada-lovecraft / gist:b991358d44cdda787f68
Created August 7, 2014 17:20
Basic Prototypical Inheritance
var Foo = function() {
this.message = "Hello, Foo!"
this.name = "Foo";
// our base class
}
Foo.prototype.sayMessage = function() {
// an instance function
console.log(this.message);
}
@ada-lovecraft
ada-lovecraft / AudioSprite.js
Created August 26, 2014 12:26
AudioSprite Implementation
'use strict';
Phaser.Loader.prototype.audiosprite = function (key, urls, atlasurl) {
this.audio(key,urls);
this.json(key+'-audioatlas', atlasurl);
};
Phaser.SoundManager.prototype.addSprite = function(key) {
var audioSprite = new Phaser.AudioSprite(this.game, key);
return audioSprite;
@ada-lovecraft
ada-lovecraft / gist:a78ad6e1f8beb044a47f
Created August 27, 2014 13:39
tween value and display
var foo, fooDisplay;
foo = {
value: 10;
};
fooDisplay = game.add.text(100,100,foo.toFixed(20));
function update() {
fooDisplay.text = foo.value.toFixed(2);
objectGroup = @game.add.group()
map.createFromObjects "PlatformLayer", gids.PLATFORM_HORIZONTAL, "platforms", 1, true, false, objectGroup, HorizontalPlatform
objectGroup.callAll "isReady()"