2017-02-23 03:54:54 +00:00
|
|
|
var BlitterRender = require('./BlitterRender');
|
|
|
|
var Bob = require('./Bob');
|
2017-07-04 00:59:31 +00:00
|
|
|
var Class = require('../../utils/Class');
|
|
|
|
var Components = require('../components');
|
2017-08-18 00:42:14 +00:00
|
|
|
var DisplayList = require('../../scene/plugins/DisplayList');
|
2017-07-04 00:59:31 +00:00
|
|
|
var GameObject = require('../GameObject');
|
2017-01-22 22:54:06 +00:00
|
|
|
|
|
|
|
/**
|
2017-01-24 12:55:45 +00:00
|
|
|
* A Blitter Game Object.
|
2017-01-22 22:54:06 +00:00
|
|
|
*
|
2017-01-24 12:55:45 +00:00
|
|
|
* The Blitter Game Object is a special type of Container, that contains Blitter.Bob objects.
|
2017-02-01 00:43:38 +00:00
|
|
|
* These objects can be thought of as just texture frames with a position and nothing more.
|
2017-01-24 12:55:45 +00:00
|
|
|
* Bobs don't have any update methods, or the ability to have children, or any kind of special effects.
|
2017-02-01 00:43:38 +00:00
|
|
|
* They are essentially just super-fast texture frame renderers, and the Blitter object creates and manages them.
|
2017-01-22 22:54:06 +00:00
|
|
|
*/
|
|
|
|
|
2017-02-23 03:54:54 +00:00
|
|
|
var Blitter = new Class({
|
2017-01-22 22:54:06 +00:00
|
|
|
|
2017-04-05 01:10:48 +00:00
|
|
|
Extends: GameObject,
|
|
|
|
|
2017-02-23 03:54:54 +00:00
|
|
|
Mixins: [
|
|
|
|
Components.Alpha,
|
|
|
|
Components.BlendMode,
|
2017-04-11 13:15:38 +00:00
|
|
|
Components.RenderTarget,
|
2017-02-23 03:54:54 +00:00
|
|
|
Components.ScaleMode,
|
2017-03-02 02:06:22 +00:00
|
|
|
Components.Size,
|
|
|
|
Components.Texture,
|
|
|
|
Components.Transform,
|
2017-02-23 03:54:54 +00:00
|
|
|
Components.Visible,
|
2017-06-22 02:19:03 +00:00
|
|
|
Components.ScrollFactor,
|
2017-02-23 03:54:54 +00:00
|
|
|
BlitterRender
|
|
|
|
],
|
2017-01-24 12:55:45 +00:00
|
|
|
|
2017-02-23 03:54:54 +00:00
|
|
|
initialize:
|
2017-02-13 23:57:32 +00:00
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
function Blitter (scene, x, y, texture, frame)
|
2017-02-23 03:54:54 +00:00
|
|
|
{
|
2017-07-14 13:30:20 +00:00
|
|
|
GameObject.call(this, scene, 'Blitter');
|
2017-02-13 23:57:32 +00:00
|
|
|
|
2017-02-23 03:54:54 +00:00
|
|
|
this.setTexture(texture, frame);
|
2017-03-02 02:06:22 +00:00
|
|
|
this.setPosition(x, y);
|
2017-01-22 22:54:06 +00:00
|
|
|
|
2017-07-04 00:59:31 +00:00
|
|
|
this.children = new DisplayList(this);
|
2017-01-22 22:54:06 +00:00
|
|
|
|
2017-02-23 03:54:54 +00:00
|
|
|
this.renderList = [];
|
2017-01-22 22:54:06 +00:00
|
|
|
|
2017-02-23 03:54:54 +00:00
|
|
|
this.dirty = false;
|
|
|
|
},
|
2017-02-01 00:43:38 +00:00
|
|
|
|
2017-02-23 03:54:54 +00:00
|
|
|
// frame MUST be part of the Blitter texture
|
|
|
|
create: function (x, y, frame, visible, index)
|
2017-02-01 00:43:38 +00:00
|
|
|
{
|
2017-02-23 03:54:54 +00:00
|
|
|
if (visible === undefined) { visible = true; }
|
|
|
|
if (index === undefined) { index = this.children.length; }
|
2017-01-22 22:54:06 +00:00
|
|
|
|
2017-08-14 12:13:27 +00:00
|
|
|
if (frame === undefined)
|
|
|
|
{
|
|
|
|
frame = this.frame;
|
|
|
|
}
|
|
|
|
else
|
2017-02-23 03:54:54 +00:00
|
|
|
{
|
|
|
|
frame = this.texture.get(frame);
|
|
|
|
}
|
2017-01-22 22:54:06 +00:00
|
|
|
|
2017-10-02 13:50:02 +00:00
|
|
|
var bob = new Bob(this, x, y, frame, visible);
|
2017-01-22 22:54:06 +00:00
|
|
|
|
2017-02-23 03:54:54 +00:00
|
|
|
this.children.addAt(bob, index, false);
|
2017-02-13 23:57:32 +00:00
|
|
|
|
2017-02-23 03:54:54 +00:00
|
|
|
this.dirty = true;
|
2017-01-22 22:54:06 +00:00
|
|
|
|
2017-02-23 03:54:54 +00:00
|
|
|
return bob;
|
|
|
|
},
|
2017-01-24 12:55:45 +00:00
|
|
|
|
2017-02-23 03:54:54 +00:00
|
|
|
// frame MUST be part of the Blitter texture
|
|
|
|
createFromCallback: function (callback, quantity, frame, visible)
|
2017-01-24 12:55:45 +00:00
|
|
|
{
|
2017-02-23 03:54:54 +00:00
|
|
|
var bobs = this.createMultiple(quantity, frame, visible);
|
2017-01-22 22:54:06 +00:00
|
|
|
|
2017-02-23 03:54:54 +00:00
|
|
|
for (var i = 0; i < bobs.length; i++)
|
|
|
|
{
|
|
|
|
var bob = bobs[i];
|
2017-01-22 22:54:06 +00:00
|
|
|
|
2017-02-23 03:54:54 +00:00
|
|
|
callback.call(this, bob, i);
|
|
|
|
}
|
2017-01-22 22:54:06 +00:00
|
|
|
|
2017-02-23 03:54:54 +00:00
|
|
|
return bobs;
|
|
|
|
},
|
2017-01-22 22:54:06 +00:00
|
|
|
|
2017-02-23 03:54:54 +00:00
|
|
|
// frame MUST be part of the Blitter texture
|
|
|
|
createMultiple: function (quantity, frame, visible)
|
2017-01-24 12:55:45 +00:00
|
|
|
{
|
2017-02-23 03:54:54 +00:00
|
|
|
if (frame === undefined) { frame = this.frame; }
|
|
|
|
if (visible === undefined) { visible = true; }
|
|
|
|
|
|
|
|
if (!Array.isArray(frame))
|
|
|
|
{
|
|
|
|
frame = [ frame ];
|
|
|
|
}
|
2017-01-22 22:54:06 +00:00
|
|
|
|
2017-02-23 03:54:54 +00:00
|
|
|
var bobs = [];
|
|
|
|
var _this = this;
|
2017-01-24 12:55:45 +00:00
|
|
|
|
2017-02-23 03:54:54 +00:00
|
|
|
frame.forEach(function (singleFrame)
|
|
|
|
{
|
|
|
|
for (var i = 0; i < quantity; i++)
|
|
|
|
{
|
|
|
|
bobs.push(_this.create(0, 0, singleFrame, visible));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return bobs;
|
|
|
|
},
|
|
|
|
|
|
|
|
childCanRender: function (child)
|
2017-01-24 12:55:45 +00:00
|
|
|
{
|
2017-02-23 03:54:54 +00:00
|
|
|
return (child.visible && child.alpha > 0);
|
|
|
|
},
|
|
|
|
|
|
|
|
getRenderList: function ()
|
|
|
|
{
|
|
|
|
if (this.dirty)
|
2017-01-22 22:54:06 +00:00
|
|
|
{
|
2017-02-23 03:54:54 +00:00
|
|
|
this.renderList = this.children.list.filter(this.childCanRender, this);
|
|
|
|
this.dirty = false;
|
2017-01-22 22:54:06 +00:00
|
|
|
}
|
|
|
|
|
2017-02-23 03:54:54 +00:00
|
|
|
return this.renderList;
|
|
|
|
},
|
2017-01-22 22:54:06 +00:00
|
|
|
|
2017-02-23 03:54:54 +00:00
|
|
|
clear: function ()
|
2017-02-13 23:57:32 +00:00
|
|
|
{
|
2017-02-23 03:54:54 +00:00
|
|
|
this.children.removeAll();
|
|
|
|
this.dirty = true;
|
2017-02-13 23:57:32 +00:00
|
|
|
}
|
|
|
|
|
2017-02-23 03:54:54 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = Blitter;
|