mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 13:13:43 +00:00
Added Blitter Game Object, for fast drawing of texture frames, with single level transforms.
This commit is contained in:
parent
67eb8753e8
commit
e150efea1f
4 changed files with 146 additions and 0 deletions
61
src/gameobjects/blitter/Blitter.js
Normal file
61
src/gameobjects/blitter/Blitter.js
Normal file
|
@ -0,0 +1,61 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
Phaser.GameObject.Blitter = function (state, parent)
|
||||
{
|
||||
Phaser.GameObject.call(this, state, 0, 0, null, null, parent);
|
||||
|
||||
this.type = Phaser.BLITTER;
|
||||
|
||||
this.children = new Phaser.Component.Children(this);
|
||||
};
|
||||
|
||||
Phaser.GameObject.Blitter.prototype = Object.create(Phaser.GameObject.prototype);
|
||||
Phaser.GameObject.Blitter.prototype.constructor = Phaser.GameObject.Blitter;
|
||||
|
||||
Phaser.GameObject.Blitter.prototype.preUpdate = function ()
|
||||
{
|
||||
if (this.parent)
|
||||
{
|
||||
this.color.worldAlpha = this.parent.color.worldAlpha;
|
||||
}
|
||||
};
|
||||
|
||||
Phaser.GameObject.Blitter.prototype.create = function (frame, x, y, visible, index)
|
||||
{
|
||||
if (x === undefined) { x = 0; }
|
||||
if (y === undefined) { y = 0; }
|
||||
if (visible === undefined) { visible = true; }
|
||||
if (index === undefined) { index = 0; }
|
||||
|
||||
var bob = new Phaser.GameObject.Blitter.Bob(this, frame, x, y, visible);
|
||||
|
||||
this.children.addAt(bob, index, true);
|
||||
|
||||
return bob;
|
||||
};
|
||||
|
||||
Phaser.GameObject.Blitter.prototype.createMultiple = function (quantity, frame, visible)
|
||||
{
|
||||
if (visible === undefined) { visible = true; }
|
||||
|
||||
if (!Array.isArray(frame))
|
||||
{
|
||||
frame = [ frame ];
|
||||
}
|
||||
|
||||
var bobs = [];
|
||||
|
||||
for (var f = 0; f < frame.length; f++)
|
||||
{
|
||||
for (var i = 0; i < quantity; i++)
|
||||
{
|
||||
bobs.push(this.create(frame[f], 0, 0, visible));
|
||||
}
|
||||
}
|
||||
|
||||
return bobs;
|
||||
};
|
19
src/gameobjects/blitter/BlitterFactory.js
Normal file
19
src/gameobjects/blitter/BlitterFactory.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
Phaser.GameObject.Blitter.FACTORY_KEY = 'blitter';
|
||||
|
||||
Phaser.GameObject.Blitter.FACTORY_ADD = function (parent)
|
||||
{
|
||||
if (parent === undefined) { parent = this.state; }
|
||||
|
||||
return parent.children.add(new Phaser.GameObject.Blitter(this.state, parent));
|
||||
};
|
||||
|
||||
Phaser.GameObject.Blitter.FACTORY_MAKE = function (parent)
|
||||
{
|
||||
return new Phaser.GameObject.Blitter(this.state, parent);
|
||||
};
|
28
src/gameobjects/blitter/BlitterWebGLRenderer.js
Normal file
28
src/gameobjects/blitter/BlitterWebGLRenderer.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
Phaser.Renderer.WebGL.GameObjects.Blitter = {
|
||||
|
||||
TYPES: [
|
||||
Phaser.GameObject.Blitter.prototype
|
||||
],
|
||||
|
||||
render: function (renderer, src)
|
||||
{
|
||||
var alpha = src.color.worldAlpha * 255 << 24;
|
||||
|
||||
// Skip rendering?
|
||||
// if (src.skipRender || !src.visible || alpha === 0 || src.children.list.length === 0)
|
||||
if (src.skipRender || !src.visible || alpha === 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Render children
|
||||
// for (var i = 0; i < src.children.list.length; i++)
|
||||
// {
|
||||
// var child = src.children.list[i];
|
||||
|
||||
// child.render(renderer, child);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
};
|
38
src/gameobjects/blitter/Bob.js
Normal file
38
src/gameobjects/blitter/Bob.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
Phaser.GameObject.Blitter.Bob = function (parent, frame, x, y, visible)
|
||||
{
|
||||
if (x === undefined) { x = 0; }
|
||||
if (y === undefined) { y = 0; }
|
||||
if (visible === undefined) { visible = true; }
|
||||
|
||||
this.parent = parent;
|
||||
|
||||
this.texture = frame.texture;
|
||||
|
||||
this.frame = frame;
|
||||
|
||||
this.type = 0;
|
||||
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.scaleX = 1;
|
||||
this.scaleY = 1;
|
||||
this.rotation = 0;
|
||||
this.pivotX = 0;
|
||||
this.pivotY = 0;
|
||||
this.anchorX = 0;
|
||||
this.anchorY = 0;
|
||||
|
||||
this.alpha = 1;
|
||||
|
||||
this.scaleMode = Phaser.scaleModes.DEFAULT;
|
||||
|
||||
this.visible = visible;
|
||||
};
|
||||
|
||||
Phaser.GameObject.Blitter.Bob.prototype.constructor = Phaser.GameObject.Blitter.Bob;
|
Loading…
Reference in a new issue