mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 21:24:09 +00:00
Updated base game objects.
This commit is contained in:
parent
60d348c464
commit
582d705b1f
6 changed files with 99 additions and 101 deletions
|
@ -19,24 +19,24 @@
|
|||
*/
|
||||
Phaser.GameObject.Image = function (game, x, y, key, frame)
|
||||
{
|
||||
Phaser.Component.BaseTransform.call(this, x, y);
|
||||
|
||||
this.game = game;
|
||||
|
||||
Phaser.Component.BaseTransform.call(this, x, y);
|
||||
|
||||
/**
|
||||
* @property {number} type - The const type of this object.
|
||||
* @readonly
|
||||
*/
|
||||
this.type = Phaser.IMAGE;
|
||||
|
||||
this.name = '';
|
||||
|
||||
this.parent = null;
|
||||
|
||||
this.texture = game.textures.get(key);
|
||||
|
||||
this.frame = this.texture.get(frame);
|
||||
|
||||
this.children = new Phaser.Component.Children(this);
|
||||
|
||||
// Allows you to turn off a GO from rendering, but still render its children
|
||||
this.skipRender = (key === undefined);
|
||||
|
||||
|
@ -62,8 +62,7 @@ Phaser.GameObject.Image.prototype.constructor = Phaser.GameObject.Image;
|
|||
*/
|
||||
Phaser.GameObject.Image.prototype.preUpdate = function ()
|
||||
{
|
||||
this.transform.update();
|
||||
// this.children.update();
|
||||
// this.transform.update();
|
||||
};
|
||||
|
||||
Phaser.GameObject.Image.prototype.update = function ()
|
||||
|
|
|
@ -73,14 +73,6 @@ Phaser.Renderer.Canvas.GameObjects.Image = {
|
|||
|
||||
renderer.context.drawImage(source.image, frame.cutX, frame.cutY, cw, ch, dx, dy, cw / resolution, ch / resolution);
|
||||
|
||||
// TEMP TEST!
|
||||
for (var i = 0; i < src.children.list.length; i++)
|
||||
{
|
||||
var child = src.children.list[i];
|
||||
|
||||
child.render(renderer, child);
|
||||
}
|
||||
|
||||
/*
|
||||
// Move this to either the Renderer, or the Texture Manager, but not here (as it's repeated all over the place)
|
||||
if (src.texture.rotated)
|
||||
|
|
|
@ -8,10 +8,10 @@ Phaser.GameObject.Image.FACTORY_KEY = 'image';
|
|||
|
||||
/**
|
||||
* Create a new `Image` object.
|
||||
*
|
||||
*
|
||||
* An Image is a light-weight object you can use to display anything that doesn't need physics or animation.
|
||||
*
|
||||
* It can still rotate, scale, crop and receive input events.
|
||||
*
|
||||
* It can still rotate, scale, crop and receive input events.
|
||||
* This makes it perfect for logos, backgrounds, simple buttons and other non-Sprite graphics.
|
||||
*
|
||||
* @method Phaser.GameObject.Factory#image
|
||||
|
|
|
@ -13,28 +13,7 @@
|
|||
*
|
||||
* @class Phaser.GameObject.Sprite
|
||||
* @constructor
|
||||
* @extends PIXI.Sprite
|
||||
* @extends Phaser.Component.Core
|
||||
* @extends Phaser.Component.Angle
|
||||
* @extends Phaser.Component.Animation
|
||||
* @extends Phaser.Component.AutoCull
|
||||
* @extends Phaser.Component.Bounds
|
||||
* @extends Phaser.Component.BringToTop
|
||||
* @extends Phaser.Component.Crop
|
||||
* @extends Phaser.Component.Delta
|
||||
* @extends Phaser.Component.Destroy
|
||||
* @extends Phaser.Component.FixedToCamera
|
||||
* @extends Phaser.Component.Health
|
||||
* @extends Phaser.Component.InCamera
|
||||
* @extends Phaser.Component.InputEnabled
|
||||
* @extends Phaser.Component.InWorld
|
||||
* @extends Phaser.Component.LifeSpan
|
||||
* @extends Phaser.Component.LoadTexture
|
||||
* @extends Phaser.Component.Overlap
|
||||
* @extends Phaser.Component.PhysicsBody
|
||||
* @extends Phaser.Component.Reset
|
||||
* @extends Phaser.Component.ScaleMinMax
|
||||
* @extends Phaser.Component.Smoothed
|
||||
* @extends Phaser.Components.BaseTransform
|
||||
* @param {Phaser.Game} game - A reference to the currently running game.
|
||||
* @param {number} x - The x coordinate (in world space) to position the Sprite at.
|
||||
* @param {number} y - The y coordinate (in world space) to position the Sprite at.
|
||||
|
@ -43,8 +22,9 @@
|
|||
*/
|
||||
Phaser.GameObject.Sprite = function (game, x, y, key, frame)
|
||||
{
|
||||
x = x || 0;
|
||||
y = y || 0;
|
||||
this.game = game;
|
||||
|
||||
Phaser.Component.BaseTransform.call(this, x, y);
|
||||
|
||||
/**
|
||||
* @property {number} type - The const type of this object.
|
||||
|
@ -58,56 +38,84 @@ Phaser.GameObject.Sprite = function (game, x, y, key, frame)
|
|||
*/
|
||||
this.physicsType = Phaser.SPRITE;
|
||||
|
||||
PIXI.Sprite.call(this, Phaser.Cache.DEFAULT);
|
||||
this.name = '';
|
||||
|
||||
Phaser.Component.Core.init.call(this, game, x, y, key, frame);
|
||||
this.parent = null;
|
||||
|
||||
this.texture = game.textures.get(key);
|
||||
|
||||
this.frame = this.texture.get(frame);
|
||||
|
||||
this.children = new Phaser.Component.Children(this);
|
||||
|
||||
// Allows you to turn off a GO from rendering, but still render its children
|
||||
this.skipRender = (key === undefined);
|
||||
|
||||
this.visible = true;
|
||||
|
||||
this.data = new Phaser.Component.Data(this);
|
||||
|
||||
// Temporary for now?
|
||||
this.alpha = 1;
|
||||
this.blendMode = Phaser.blendModes.NORMAL;
|
||||
this.scaleMode = Phaser.scaleModes.DEFAULT;
|
||||
this.exists = true;
|
||||
};
|
||||
|
||||
Phaser.GameObject.Sprite.prototype = Object.create(PIXI.Sprite.prototype);
|
||||
Phaser.GameObject.Sprite.prototype = Object.create(Phaser.Component.BaseTransform.prototype);
|
||||
Phaser.GameObject.Sprite.prototype.constructor = Phaser.GameObject.Sprite;
|
||||
|
||||
Phaser.Component.Core.install.call(Phaser.GameObject.Sprite.prototype, [
|
||||
'Angle',
|
||||
'Animation',
|
||||
'AutoCull',
|
||||
'Bounds',
|
||||
'BringToTop',
|
||||
'Crop',
|
||||
'Delta',
|
||||
'Destroy',
|
||||
'FixedToCamera',
|
||||
'Health',
|
||||
'InCamera',
|
||||
'InputEnabled',
|
||||
'InWorld',
|
||||
'LifeSpan',
|
||||
'Overlap',
|
||||
'PhysicsBody',
|
||||
'Reset',
|
||||
'ScaleMinMax',
|
||||
'Smoothed'
|
||||
]);
|
||||
|
||||
Phaser.GameObject.Sprite.prototype.preUpdatePhysics = Phaser.Component.PhysicsBody.preUpdate;
|
||||
Phaser.GameObject.Sprite.prototype.preUpdateLifeSpan = Phaser.Component.LifeSpan.preUpdate;
|
||||
Phaser.GameObject.Sprite.prototype.preUpdateInWorld = Phaser.Component.InWorld.preUpdate;
|
||||
Phaser.GameObject.Sprite.prototype.preUpdateCore = Phaser.Component.Core.preUpdate;
|
||||
|
||||
/**
|
||||
* Automatically called by World.preUpdate.
|
||||
*
|
||||
* @method
|
||||
* @memberof Phaser.GameObject.Sprite
|
||||
* @return {boolean} True if the Sprite was rendered, otherwise false.
|
||||
* @method Phaser.Sprite#preUpdate
|
||||
* @memberof Phaser.Sprite
|
||||
*/
|
||||
Phaser.GameObject.Sprite.prototype.preUpdate = function () {
|
||||
Phaser.GameObject.Sprite.prototype.preUpdate = function ()
|
||||
{
|
||||
// this.transform.update();
|
||||
};
|
||||
|
||||
Phaser.GameObject.Sprite.prototype.update = function ()
|
||||
{
|
||||
};
|
||||
|
||||
Phaser.GameObject.Sprite.prototype.postUpdate = function ()
|
||||
{
|
||||
};
|
||||
|
||||
Object.defineProperties(Phaser.GameObject.Sprite.prototype, {
|
||||
|
||||
width: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._scaleX * this.frame.realWidth;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.scaleX = value / this.frame.realWidth;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
height: {
|
||||
|
||||
enumerable: true,
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this.transform._scaleY * this.frame.realHeight;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.scaleY = value / this.frame.realHeight;
|
||||
}
|
||||
|
||||
if (!this.preUpdatePhysics() || !this.preUpdateLifeSpan() || !this.preUpdateInWorld())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.preUpdateCore();
|
||||
|
||||
};
|
||||
});
|
||||
|
|
|
@ -8,8 +8,7 @@
|
|||
Phaser.Renderer.Canvas.GameObjects.Sprite = {
|
||||
|
||||
TYPES: [
|
||||
Phaser.GameObject.Sprite.prototype,
|
||||
PIXI.Sprite.prototype
|
||||
Phaser.GameObject.Sprite.prototype
|
||||
],
|
||||
|
||||
render: function (renderer, src)
|
||||
|
@ -19,7 +18,7 @@ Phaser.Renderer.Canvas.GameObjects.Sprite = {
|
|||
|
||||
// Skip render?
|
||||
|
||||
if (!src.visible || !src.alpha || !src.renderable || !frame.cutWidth || !frame.cutHeight)
|
||||
if (src.skipRender || !src.visible || !src.alpha || !frame.cutWidth || !frame.cutHeight)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -32,14 +31,14 @@ Phaser.Renderer.Canvas.GameObjects.Sprite = {
|
|||
renderer.context.globalCompositeOperation = renderer.blendModes[renderer.currentBlendMode];
|
||||
}
|
||||
|
||||
// Alpha
|
||||
// Alpha (World Alpha?)
|
||||
|
||||
if (src.worldAlpha !== renderer.context.globalAlpha)
|
||||
if (src.alpha !== renderer.context.globalAlpha)
|
||||
{
|
||||
renderer.context.globalAlpha = src.worldAlpha;
|
||||
renderer.context.globalAlpha = src.alpha;
|
||||
}
|
||||
|
||||
// Smoothing (should this be a Game Object, or Frame/Texture level property?)
|
||||
// Smoothing (should this be a Game Object, or Frame / Texture level property?)
|
||||
|
||||
if (source.scaleMode !== renderer.currentScaleMode)
|
||||
{
|
||||
|
@ -47,12 +46,12 @@ Phaser.Renderer.Canvas.GameObjects.Sprite = {
|
|||
renderer.context[renderer.smoothProperty] = (source.scaleMode === Phaser.scaleModes.LINEAR);
|
||||
}
|
||||
|
||||
var wt = src.worldTransform;
|
||||
var wt = src.transform.world;
|
||||
|
||||
var resolution = source.resolution / renderer.game.resolution;
|
||||
|
||||
var dx = frame.x - (src.anchor.x * frame.width);
|
||||
var dy = frame.y - (src.anchor.y * frame.height);
|
||||
var dx = frame.x - (src.anchorX * frame.width);
|
||||
var dy = frame.y - (src.anchorY * frame.height);
|
||||
|
||||
var tx = (wt.tx * renderer.game.resolution) + renderer.game.camera._shake.x;
|
||||
var ty = (wt.ty * renderer.game.resolution) + renderer.game.camera._shake.y;
|
||||
|
@ -70,6 +69,8 @@ Phaser.Renderer.Canvas.GameObjects.Sprite = {
|
|||
var cw = frame.cutWidth;
|
||||
var ch = frame.cutHeight;
|
||||
|
||||
renderer.context.setTransform(wt.a, wt.b, wt.c, wt.d, tx, ty);
|
||||
|
||||
// Does this Sprite have a mask?
|
||||
|
||||
if (src._mask)
|
||||
|
@ -77,10 +78,15 @@ Phaser.Renderer.Canvas.GameObjects.Sprite = {
|
|||
renderer.pushMask(src._mask);
|
||||
}
|
||||
|
||||
renderer.context.setTransform(wt.a, wt.b, wt.c, wt.d, tx, ty);
|
||||
|
||||
renderer.context.drawImage(source.image, frame.cutX, frame.cutY, cw, ch, dx, dy, cw / resolution, ch / resolution);
|
||||
|
||||
for (var i = 0; i < src.children.list.length; i++)
|
||||
{
|
||||
var child = src.children.list[i];
|
||||
|
||||
child.render(renderer, child);
|
||||
}
|
||||
|
||||
/*
|
||||
// Move this to either the Renderer, or the Texture Manager, but not here (as it's repeated all over the place)
|
||||
if (src.texture.rotated)
|
||||
|
@ -121,13 +127,6 @@ Phaser.Renderer.Canvas.GameObjects.Sprite = {
|
|||
}
|
||||
*/
|
||||
|
||||
for (var i = 0; i < src.children.length; i++)
|
||||
{
|
||||
var child = src.children[i];
|
||||
|
||||
child.render(child);
|
||||
}
|
||||
|
||||
if (src._mask)
|
||||
{
|
||||
renderer.popMask();
|
||||
|
|
|
@ -25,7 +25,7 @@ Phaser.GameObject.Sprite.FACTORY_ADD = function (x, y, key, frame, group)
|
|||
{
|
||||
if (group === undefined) { group = this.world; }
|
||||
|
||||
return group.create(x, y, key, frame);
|
||||
return group.children.add(new Phaser.GameObject.Sprite(this.game, x, y, key, frame));
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue