Finished off RenderTexture. Sprites can now accept a RenderTexture or a key when you create them. RenderTextures are also now stored in the cache under their own key, making re-using them across other Sprites much easier. Also ported over all of the Tilemap classes, but need to get them rendering.

This commit is contained in:
Richard Davey
2013-09-11 02:57:36 +01:00
parent f885f7b023
commit 48ed27dfcc
11 changed files with 1292 additions and 73 deletions
+18 -9
View File
@@ -21,13 +21,13 @@ Phaser.GameObjectFactory.prototype = {
*
* @param x {number} X position of the new sprite.
* @param y {number} Y position of the new sprite.
* @param [key] {string} The image key as defined in the Game.Cache to use as the texture for this sprite
* @param [texture] {string|RenderTexture} The image key as defined in the Game.Cache to use as the texture for this sprite OR a RenderTexture
* @param [frame] {string|number} If the sprite uses an image from a texture atlas or sprite sheet you can pass the frame here. Either a number for a frame ID or a string for a frame name.
* @returns {Sprite} The newly created sprite object.
*/
sprite: function (x, y, key, frame) {
sprite: function (x, y, texture, frame) {
return this.world.add(new Phaser.Sprite(this.game, x, y, key, frame));
return this.world.add(new Phaser.Sprite(this.game, x, y, texture, frame));
},
@@ -36,13 +36,13 @@ Phaser.GameObjectFactory.prototype = {
*
* @param x {number} X position of the new sprite.
* @param y {number} Y position of the new sprite.
* @param [key] {string} The image key as defined in the Game.Cache to use as the texture for this sprite
* @param [texture] {string|RenderTexture} The image key as defined in the Game.Cache to use as the texture for this sprite OR a RenderTexture
* @param [frame] {string|number} If the sprite uses an image from a texture atlas or sprite sheet you can pass the frame here. Either a number for a frame ID or a string for a frame name.
* @returns {Sprite} The newly created sprite object.
*/
child: function (parent, x, y, key, frame) {
child: function (parent, x, y, texture, frame) {
var child = this.world.add(new Phaser.Sprite(this.game, x, y, key, frame));
var child = this.world.add(new Phaser.Sprite(this.game, x, y, texture, frame));
parent.addChild(child);
return child;
@@ -52,12 +52,11 @@ Phaser.GameObjectFactory.prototype = {
* 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) {
tween: function (obj) {
return this.game.tweens.create(obj, localReference);
return this.game.tweens.create(obj);
},
@@ -109,4 +108,14 @@ Phaser.GameObjectFactory.prototype = {
},
renderTexture: function (key, width, height) {
var texture = new Phaser.RenderTexture(this.game, key, width, height);
this.game.cache.addRenderTexture(key, texture);
return texture;
},
};
+3 -11
View File
@@ -1,17 +1,9 @@
Phaser.RenderTexture = function (game, width, height) {
// If exists = false then the Sprite isn't updated by the core game loop or physics subsystem at all
this.exists = true;
// This is a handy little var your game can use to determine if a sprite is alive or not, it doesn't effect rendering
this.alive = true;
this.group = null;
this.name = '';
Phaser.RenderTexture = function (game, key, width, height) {
this.game = game;
this.name = key;
PIXI.EventTarget.call( this );
this.width = width || 100;
+44 -27
View File
@@ -1,8 +1,8 @@
Phaser.Sprite = function (game, x, y, key, frame) {
Phaser.Sprite = function (game, x, y, texture, frame) {
x = x || 0;
y = y || 0;
key = key || null;
texture = texture || null;
frame = frame || null;
this.game = game;
@@ -23,13 +23,47 @@ Phaser.Sprite = function (game, x, y, key, frame) {
// The lifespan is decremented by game.time.elapsed each update, once it reaches zero the kill() function is called.
this.lifespan = 0;
if (key == null || this.game.cache.checkImageKey(key) == false)
if (texture instanceof Phaser.RenderTexture)
{
key = '__default';
PIXI.Sprite.call(this, texture);
this.currentFrame = this.game.cache.getTextureFrame(texture.name);
}
else
{
if (texture == null || this.game.cache.checkImageKey(texture) == false)
{
texture = '__default';
}
PIXI.Sprite.call(this, PIXI.TextureCache[texture]);
if (this.game.cache.isSpriteSheet(texture))
{
this.animations.loadFrameData(this.game.cache.getFrameData(texture));
if (frame !== null)
{
if (typeof frame === 'string')
{
this.frameName = frame;
}
else
{
this.frame = frame;
}
}
}
else
{
this.currentFrame = this.game.cache.getFrame(texture);
}
}
PIXI.Sprite.call(this, PIXI.TextureCache[key]);
/**
* The Signals you can subscribe to that are dispatched when certain things happen on this Sprite or its components
* @type Events
*/
this.events = new Phaser.Events(this);
/**
@@ -38,27 +72,10 @@ Phaser.Sprite = function (game, x, y, key, frame) {
*/
this.animations = new Phaser.AnimationManager(this);
if (this.game.cache.isSpriteSheet(key))
{
this.animations.loadFrameData(this.game.cache.getFrameData(key));
if (frame !== null)
{
if (typeof frame === 'string')
{
this.frameName = frame;
}
else
{
this.frame = frame;
}
}
}
else
{
this.currentFrame = this.game.cache.getFrame(key);
}
/**
* The Input Handler Component
* @type InputHandler
*/
this.input = new Phaser.InputHandler(this);
/**