mirror of
https://github.com/wassname/phaser.git
synced 2026-06-29 16:30:29 +08:00
Fixed the TweenManager and added support to GameObjectFactory, so you can create tweens easily now all hooked in to the internal game clock. Also added the AnimationManager into Sprite, so you can create and play animations directly from sprites nice and easily.
This commit is contained in:
+13
-3
@@ -17,14 +17,24 @@
|
||||
var bunny;
|
||||
|
||||
function preload() {
|
||||
game.load.spritesheet('ms', 'assets/sprites/metalslug_mummy37x45.png', 37, 45);
|
||||
// 37x45 is the size of each frame
|
||||
// There are 18 frames in the PNG - you can leave this value blank if the frames fill up the entire PNG, but in this case there are some
|
||||
// blank frames at the end, so we tell the loader how many to load
|
||||
game.load.spritesheet('ms', 'assets/sprites/metalslug_mummy37x45.png', 37, 45, 18);
|
||||
}
|
||||
|
||||
function create() {
|
||||
|
||||
bunny = new Phaser.Sprite(game, 0, 0, 'ms', 10);
|
||||
bunny = game.add.sprite(-40, 100, 'ms');
|
||||
|
||||
game.world.add(bunny);
|
||||
bunny.animations.add('walk');
|
||||
|
||||
bunny.animations.play('walk', 50, true);
|
||||
|
||||
// bunny.scale.x = 8;
|
||||
// bunny.scale.y = 8;
|
||||
|
||||
game.add.tween(bunny).to({ x: game.width }, 10000, Phaser.Easing.Linear.None, true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -61,16 +61,17 @@ Phaser.AnimationManager.prototype = {
|
||||
|
||||
if (this._frameData == null)
|
||||
{
|
||||
console.warn('No frameData available for Phaser.Animation ' + name);
|
||||
return;
|
||||
}
|
||||
|
||||
// Create the signals the AnimationManager will emit
|
||||
if (this._parent.events.onAnimationStart == null)
|
||||
{
|
||||
// if (this._parent.events.onAnimationStart == null)
|
||||
// {
|
||||
// this._parent.events.onAnimationStart = new Phaser.Signal();
|
||||
// this._parent.events.onAnimationComplete = new Phaser.Signal();
|
||||
// this._parent.events.onAnimationLoop = new Phaser.Signal();
|
||||
}
|
||||
// }
|
||||
|
||||
if (frames == null)
|
||||
{
|
||||
@@ -243,7 +244,6 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "frame", {
|
||||
{
|
||||
this.currentFrame = this._frameData.getFrame(value);
|
||||
this._frameIndex = value;
|
||||
console.log('AM set frame', value, this.currentFrame);
|
||||
this._parent.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,10 +21,12 @@ Phaser.World.prototype = {
|
||||
|
||||
add: function (gameobject) {
|
||||
this._container.addChild(gameobject);
|
||||
return gameobject;
|
||||
},
|
||||
|
||||
addAt: function (gameobject, index) {
|
||||
this._container.addChildAt(gameobject, index);
|
||||
return gameobject;
|
||||
},
|
||||
|
||||
getAt: function (index) {
|
||||
@@ -33,6 +35,7 @@ Phaser.World.prototype = {
|
||||
|
||||
remove: function (gameobject) {
|
||||
this._container.removeChild(gameobject);
|
||||
return gameobject;
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
Phaser.GameObjectFactory = function (game) {
|
||||
|
||||
this.game = game;
|
||||
this._world = this.game.world;
|
||||
this.world = this.game.world;
|
||||
|
||||
};
|
||||
|
||||
Phaser.GameObjectFactory.prototype = {
|
||||
|
||||
_world: null,
|
||||
game: null,
|
||||
world: null,
|
||||
|
||||
/**
|
||||
* Create a new Sprite with specific position and sprite sheet key.
|
||||
@@ -24,8 +24,23 @@ Phaser.GameObjectFactory.prototype = {
|
||||
if (typeof key === "undefined") { key = ''; }
|
||||
if (typeof frame === "undefined") { frame = null; }
|
||||
|
||||
// return this._world.group.add(new Phaser.Sprite(this.game, x, y, key, frame));
|
||||
return this.world.add(new Phaser.Sprite(this.game, x, y, key, frame));
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Create a tween object for a specific object. The object can be any JavaScript object or Phaser object such as Sprite.
|
||||
*
|
||||
* @param obj {object} Object the tween will be run on.
|
||||
* @param [localReference] {bool} If true the tween will be stored in the object.tween property so long as it exists. If already set it'll be over-written.
|
||||
* @return {Phaser.Tween} The newly created tween object.
|
||||
*/
|
||||
tween: function (obj, localReference) {
|
||||
|
||||
if (typeof localReference === "undefined") { localReference = false; }
|
||||
|
||||
return this.game.tweens.create(obj, localReference);
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
@@ -47,9 +47,14 @@ Phaser.Sprite = function (game, x, y, key, frame) {
|
||||
*/
|
||||
this.texture = PIXI.TextureCache[key];
|
||||
|
||||
if (this.game.cache.isSpriteSheet(key))
|
||||
{
|
||||
this.animations.loadFrameData(this.game.cache.getFrameData(key));
|
||||
}
|
||||
|
||||
if (frame !== null)
|
||||
{
|
||||
if (typeof frame == 'string')
|
||||
if (typeof frame === 'string')
|
||||
{
|
||||
this.frameName = frame;
|
||||
}
|
||||
|
||||
+6
-10
@@ -41,8 +41,7 @@ Phaser.Tween = function (object, game) {
|
||||
this._valuesStart[ field ] = parseFloat(object[field], 10);
|
||||
}
|
||||
|
||||
// this.onStart = new Phaser.Signal();
|
||||
// this.onUpdate = new Phaser.Signal();
|
||||
this.onStart = new Phaser.Signal();
|
||||
this.onComplete = new Phaser.Signal();
|
||||
|
||||
this.isRunning = false;
|
||||
@@ -93,12 +92,14 @@ Phaser.Tween.prototype = {
|
||||
|
||||
start: function ( time ) {
|
||||
|
||||
//TWEEN.add( this );
|
||||
|
||||
if (this.game === null || this._object === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._manager.add(this);
|
||||
|
||||
this.onStart.dispatch(this._object);
|
||||
|
||||
this.isRunning = true;
|
||||
|
||||
this._onStartCallbackFired = false;
|
||||
@@ -139,11 +140,7 @@ Phaser.Tween.prototype = {
|
||||
|
||||
stop: function () {
|
||||
|
||||
//TWEEN.remove( this );
|
||||
if (this._manager !== null) {
|
||||
this._manager.remove(this);
|
||||
}
|
||||
|
||||
this._manager.remove(this);
|
||||
this.isRunning = false;
|
||||
|
||||
return this;
|
||||
@@ -171,7 +168,6 @@ Phaser.Tween.prototype = {
|
||||
|
||||
},
|
||||
|
||||
|
||||
easing: function ( easing ) {
|
||||
|
||||
this._easingFunction = easing;
|
||||
|
||||
@@ -26,7 +26,7 @@ Phaser.TweenManager.prototype = {
|
||||
*/
|
||||
getAll: function () {
|
||||
|
||||
return _tweens;
|
||||
return this._tweens;
|
||||
|
||||
},
|
||||
|
||||
@@ -35,7 +35,7 @@ Phaser.TweenManager.prototype = {
|
||||
*/
|
||||
removeAll: function () {
|
||||
|
||||
_tweens = [];
|
||||
this._tweens = [];
|
||||
|
||||
},
|
||||
|
||||
@@ -47,7 +47,7 @@ Phaser.TweenManager.prototype = {
|
||||
*/
|
||||
add: function ( tween ) {
|
||||
|
||||
_tweens.push( tween );
|
||||
this._tweens.push( tween );
|
||||
|
||||
},
|
||||
|
||||
@@ -81,11 +81,11 @@ Phaser.TweenManager.prototype = {
|
||||
*/
|
||||
remove: function ( tween ) {
|
||||
|
||||
var i = _tweens.indexOf( tween );
|
||||
var i = this._tweens.indexOf( tween );
|
||||
|
||||
if ( i !== -1 ) {
|
||||
|
||||
_tweens.splice( i, 1 );
|
||||
this._tweens.splice( i, 1 );
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user