Skip to content

Commit

Permalink
Animation.looped has been renamed to Animation.loop. It's a boolean y…
Browse files Browse the repository at this point in the history
…ou can toggle at run-time to turn on/off animation looping.

A single Animation object now has 3 new events: onStart, onLoop and onComplete.
Animation.loopCount holds the number of times the animation has looped since it last started.
Animation.stop has a new parameter: dispatchComplete. If true it'll dispatch an Animation.onComplete event.
  • Loading branch information
photonstorm committed Mar 3, 2014
1 parent 4a370c8 commit 833960b
Show file tree
Hide file tree
Showing 9 changed files with 292 additions and 24 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Significant API changes:
* Game no longer pauses if you've forced orientation and change it, also doesn't resize a NO_SCALE game.
* All the Debug methods have had the word 'render' removed from the start. So where you did `debug.renderSpriteInfo` before, it's now just `debug.spriteInfo`.
* Debug methods that rendered geometry (Rectangle, Circle, Line, Point) have been merged into the single method: `Debug.geom`.
* Animation.looped has been renamed to Animation.loop. It's a boolean you can toggle at run-time to turn on/off animation looping.


New features:
Expand Down Expand Up @@ -136,7 +137,8 @@ New features:
* Device.windowsPhone is now tested for.
* The Debug panel now works in WebGL mode. Pay attention to the warning at the top of the Debug docs (feature request #499)
* You can now create blank Tilemaps and then populate them with data later.

* A single Animation object now has 3 new events: onStart, onLoop and onComplete.
* Animation.loopCount holds the number of times the animation has looped since it last started.

Updates:

Expand All @@ -163,6 +165,7 @@ Updates:
* Tween no longer copies all the object properties into the `_valuesStart` object on creation.
* Completely empty Tilemaps can now be created. This allows for dynamic map generation at runtime.
* Keyboard.event now stores the most recent DOM keyboard event.
* Animation.stop has a new parameter: dispatchComplete. If true it'll dispatch an Animation.onComplete event.


Bug Fixes:
Expand Down
69 changes: 69 additions & 0 deletions examples/animation/animation events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update });

function preload() {

game.load.image('lazur', 'assets/pics/thorn_lazur.png');
game.load.spritesheet('mummy', 'assets/sprites/metalslug_mummy37x45.png', 37, 45, 18);

}

var back;
var mummy;
var anim;
var loopText;

function create() {

game.stage.smoothed = false;

back = game.add.image(0, -400, 'lazur');
back.scale.set(2);

mummy = game.add.sprite(200, 360, 'mummy', 5);
mummy.scale.set(4);

anim = mummy.animations.add('walk');

anim.onStart.add(animationStarted, this);
anim.onLoop.add(animationLooped, this);
anim.onComplete.add(animationStopped, this);

anim.play(10, true);

}

function animationStarted(sprite, animation) {

game.add.text(32, 32, 'Animation started', { fill: 'white' });

}

function animationLooped(sprite, animation) {

if (animation.loopCount === 1)
{
loopText = game.add.text(32, 64, 'Animation looped', { fill: 'white' });
}
else
{
loopText.text = 'Animation looped x2';
animation.loop = false;
}

}

function animationStopped(sprite, animation) {

game.add.text(32, 64+32, 'Animation stopped', { fill: 'white' });

}

function update() {

if (anim.isPlaying)
{
back.x -= 1;
}

}
Binary file removed examples/assets/pics/havoc-plastic_surgery.png
Binary file not shown.
Binary file removed examples/assets/pics/title_page.png
Binary file not shown.
5 changes: 2 additions & 3 deletions examples/display/bitmapdata wobble.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ function update() {
// This creates a simple sine-wave effect running through our BitmapData.
// This is then duplicated across all 100 sprites using it, meaning we only have to calculate it and upload it to the GPU once.

function updateWobblyBall()
{

function updateWobblyBall() {

var s = 0;
var copyRect = { x: 0, y: 0, w: wavePixelChunk, h: 32 };
Expand Down Expand Up @@ -76,4 +74,5 @@ function updateWobblyBall()
{
waveDataCounter = 0;
}

}
69 changes: 69 additions & 0 deletions examples/wip/animation events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update });

function preload() {

game.load.image('lazur', 'assets/pics/thorn_lazur.png');
game.load.spritesheet('mummy', 'assets/sprites/metalslug_mummy37x45.png', 37, 45, 18);

}

var back;
var mummy;
var anim;
var loopText;

function create() {

game.stage.smoothed = false;

back = game.add.image(0, -400, 'lazur');
back.scale.set(2);

mummy = game.add.sprite(200, 360, 'mummy', 5);
mummy.scale.set(4);

anim = mummy.animations.add('walk');

anim.onStart.add(animationStarted, this);
anim.onLoop.add(animationLooped, this);
anim.onComplete.add(animationStopped, this);

anim.play(10, true);

}

function animationStarted(sprite, animation) {

game.add.text(32, 32, 'Animation started', { fill: 'white' });

}

function animationLooped(sprite, animation) {

if (animation.loopCount === 1)
{
loopText = game.add.text(32, 64, 'Animation looped', { fill: 'white' });
}
else
{
loopText.text = 'Animation looped x2';
animation.loop = false;
}

}

function animationStopped(sprite, animation) {

game.add.text(32, 64+32, 'Animation stopped', { fill: 'white' });

}

function update() {

if (anim.isPlaying)
{
back.x -= 1;
}

}
89 changes: 89 additions & 0 deletions examples/wip/tilemap put tile update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@

var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
// var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });

function preload() {

game.load.tilemap('map', 'assets/tilemaps/maps/collision_test.json', null, Phaser.Tilemap.TILED_JSON);
game.load.image('ground_1x1', 'assets/tilemaps/tiles/ground_1x1.png');
game.load.image('walls_1x2', 'assets/tilemaps/tiles/walls_1x2.png');
game.load.image('tiles2', 'assets/tilemaps/tiles/tiles2.png');
game.load.image('player', 'assets/sprites/phaser-dude.png');
game.load.image('box', 'assets/sprites/ufo.png');
game.load.image('ship', 'assets/sprites/thrust_ship2.png');

}

var ship;
var map;
var tileset;
var layer;
var p;
var b;
var cursors;
var box2;
var dump;

function create() {

game.renderer.roundPixels = true;

// game.stage.backgroundColor = '#787878';

map = game.add.tilemap('map');

map.addTilesetImage('ground_1x1');
map.addTilesetImage('walls_1x2');
map.addTilesetImage('tiles2');

layer = map.createLayer('Tile Layer 1');

layer.resizeWorld();

map.setCollisionBetween(1, 12);

layer.debug = true;

// dump = map.generateCollisionData(layer);



box2 = game.add.sprite(200, 200, 'box');
box2.physicsEnabled = true;
box2.body.fixedRotation = true;

game.camera.follow(box2);

cursors = game.input.keyboard.createCursorKeys();

}

function update() {

if (cursors.left.isDown)
{
box2.body.moveLeft(200);
}
else if (cursors.right.isDown)
{
box2.body.moveRight(200);
}
else
{
box2.body.setZeroVelocity();
}

if (cursors.up.isDown)
{
box2.body.moveUp(200);
}
else if (cursors.down.isDown)
{
box2.body.moveDown(200);
}

}

function render() {

}
Loading

0 comments on commit 833960b

Please sign in to comment.