mirror of
https://github.com/wassname/phaser.git
synced 2026-06-27 16:10:15 +08:00
Animation.speed added. You can now change the animation speed on the fly, without re-starting the animation (feature request #458)
This commit is contained in:
@@ -124,6 +124,7 @@ New features:
|
||||
* Phaser.Timer.stop has a new parameter: clearEvents (default true), if true all the events in Timer will be cleared, otherwise they will remain (fixes #383)
|
||||
* All GameObjects now have a 'destroyChildren' boolean as a parameter to their destroy method. It's default is true and the value propogates down its children.
|
||||
* Pixi GrayFilter ported over (thanks nickryall #404)
|
||||
* Animation.speed added. You can now change the animation speed on the fly, without re-starting the animation (feature request #458)
|
||||
|
||||
|
||||
Updates:
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.spritesheet('mummy', 'assets/sprites/metalslug_mummy37x45.png', 37, 45, 18);
|
||||
|
||||
}
|
||||
|
||||
var mummy;
|
||||
var anim;
|
||||
|
||||
function create() {
|
||||
|
||||
game.stage.backgroundColor = 0x2d2d2d;
|
||||
|
||||
mummy = game.add.sprite(300, 200, 'mummy', 5);
|
||||
|
||||
anim = mummy.animations.add('walk');
|
||||
|
||||
anim.play(10, true);
|
||||
|
||||
game.input.onDown.add(changeSpeed, this);
|
||||
|
||||
}
|
||||
|
||||
function changeSpeed(pointer) {
|
||||
|
||||
if (pointer.x < 400)
|
||||
{
|
||||
anim.speed -= 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
anim.speed += 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderText(anim.speed, 32, 32);
|
||||
|
||||
}
|
||||
@@ -466,6 +466,29 @@ Object.defineProperty(Phaser.Animation.prototype, 'frame', {
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.Animation#speed
|
||||
* @property {number} speed - Gets or sets the current speed of the animation, the time between each frame of the animation, given in ms. Takes effect from the NEXT frame. Minimum value is 1.
|
||||
*/
|
||||
Object.defineProperty(Phaser.Animation.prototype, 'speed', {
|
||||
|
||||
get: function () {
|
||||
|
||||
return Math.round(1000 / this.delay);
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
if (value >= 1)
|
||||
{
|
||||
this.delay = 1000 / value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* Really handy function for when you are creating arrays of animation data but it's using frame names and not numbers.
|
||||
* For example imagine you've got 30 frames named: 'explosion_0001-large' to 'explosion_0030-large'
|
||||
|
||||
Reference in New Issue
Block a user