phaser/v3/src/gameobjects/layer/Layer.js

78 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-03-22 23:16:44 +00:00
var Class = require('../../utils/Class');
var Set = require('../../structs/Set');
var Actions = require('./actions/');
2017-03-22 23:16:44 +00:00
var Layer = new Class({
Mixins: [
Actions.IncX,
Actions.IncY,
Actions.IncXY,
Actions.SetX,
Actions.SetY,
Actions.SetXY,
Actions.Rotate,
Actions.Angle,
Actions.SetRotation,
Actions.SetVisible,
Actions.ToggleVisible,
Actions.Align
],
2017-03-22 23:16:44 +00:00
initialize:
function Layer (state, children)
2017-03-22 23:16:44 +00:00
{
this.state = state;
this.children = new Set(children);
2017-03-22 23:16:44 +00:00
},
// Layer management methods:
2017-03-22 23:16:44 +00:00
add: function (child)
2017-03-23 00:07:41 +00:00
{
this.children.set(child);
2017-03-23 00:07:41 +00:00
return this;
2017-03-22 23:16:44 +00:00
},
addMultiple: function (children)
2017-03-22 23:16:44 +00:00
{
if (Array.isArray(children))
2017-03-22 23:16:44 +00:00
{
for (var i = 0; i < children.length; i++)
{
this.children.set(children[i]);
}
2017-03-22 23:16:44 +00:00
}
2017-03-23 00:07:41 +00:00
return this;
2017-03-22 23:16:44 +00:00
},
remove: function (child)
2017-03-23 00:07:41 +00:00
{
this.children.delete(child);
2017-03-23 00:07:41 +00:00
return this;
2017-03-22 23:16:44 +00:00
},
clear: function ()
2017-03-23 00:07:41 +00:00
{
this.children.clear();
2017-03-23 00:07:41 +00:00
return this;
2017-03-22 23:16:44 +00:00
},
destroy: function ()
{
this.children.clear();
2017-03-22 23:16:44 +00:00
this.state = undefined;
this.children = undefined;
}
2017-03-22 23:16:44 +00:00
});
2017-03-23 00:07:41 +00:00
module.exports = Layer;