Added and fixed-up the Container game object.

This commit is contained in:
Richard Davey 2017-02-24 02:59:44 +00:00
parent 8262b4ec5c
commit 1cddea424e
8 changed files with 51 additions and 52 deletions

View file

@ -1,4 +1,4 @@
var CHECKSUM = {
build: '675700d0-fa33-11e6-b99d-a10bc0cf71c4'
build: '4d6475f0-fa3c-11e6-ae9b-c374376ab063'
};
module.exports = CHECKSUM;

View file

@ -1,31 +1,25 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2016 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var CONST = require('../../const');
var Class = require('../../utils/Class');
var GameObject = require('../GameObject');
var ContainerWebGLRenderer = require('./ContainerWebGLRenderer');
var Children = require('../../components/Children');
var Components = require('../../components');
var ContainerRender = require('./ContainerRender');
var Container = function (state, parent, x, y)
{
GameObject.call(this, state, x, y, null, null, parent);
var Container = new Class({
this.type = CONST.CONTAINER;
Mixins: [
Components.Visible,
ContainerRender
],
this.render = ContainerWebGLRenderer;
initialize:
this.children = new Children(this);
};
function Container (state)
{
GameObject.call(this, state);
Container.prototype = Object.create(GameObject.prototype);
Container.prototype.constructor = Container;
this.children = new Components.Children(this);
}
Container.prototype.preUpdate = function ()
{
this.children.preUpdate();
};
});
module.exports = Container;

View file

@ -0,0 +1,18 @@
var ContainerCanvasRenderer = function (renderer, src, interpolationPercentage, camera)
{
if (this.renderMask !== this.renderFlags)
{
return;
}
// Render children
for (var i = 0; i < src.children.list.length; i++)
{
var child = src.children.list[i];
child.renderCanvas(renderer, child, interpolationPercentage, camera);
}
};
module.exports = ContainerCanvasRenderer;

View file

@ -1,8 +1,3 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2016 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var Container = require('./Container');
var FactoryContainer = require('../../gameobjects/FactoryContainer');

View file

@ -0,0 +1,6 @@
module.exports = {
renderCanvas: require('./ContainerCanvasRenderer'),
renderWebGL: require('./ContainerWebGLRenderer')
};

View file

@ -1,11 +1,7 @@
var ContainerWebGLRenderer = function (renderer, src, interpolationPercentage)
var ContainerWebGLRenderer = function (renderer, src, interpolationPercentage, camera)
{
var alpha = src.color.worldAlpha * 255 << 24;
// Skip rendering?
if (src.skipRender || !src.visible || alpha === 0 || src.children.list.length === 0)
if (this.renderMask !== this.renderFlags)
{
return;
}
@ -15,7 +11,7 @@ var ContainerWebGLRenderer = function (renderer, src, interpolationPercentage)
{
var child = src.children.list[i];
child.render(renderer, child);
child.renderWebGL(renderer, child, interpolationPercentage, camera);
}
};

View file

@ -1,8 +1,3 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2016 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var Image = require('./Image');
var FactoryContainer = require('../../gameobjects/FactoryContainer');
@ -27,20 +22,15 @@ var ImageFactory = {
* @param {Phaser.Group} [group] - Optional Group to add the object to. If not specified it will be added to the World group.
* @return {Phaser.Image} The newly created Image object.
*/
add: function (x, y, key, frame, group)
add: function (x, y, key, frame, parent)
{
if (group === undefined) { group = this.state; }
if (parent === undefined) { parent = this.state; }
// console.log('ImageFactory.add', key);
// console.log('into State', this.state.sys.settings.key);
return group.children.add(new Image(this.state, x, y, key, frame));
return parent.children.add(new Image(this.state, x, y, key, frame));
},
make: function (x, y, key, frame)
{
// console.log('ImageFactory.make', key, x, y, frame);
return new Image(this.state, x, y, key, frame);
}

View file

@ -1,21 +1,21 @@
// Required, but don't need Phaser level exports
// (maybe these should be Phaser export level?)
require('./blitter/BlitterFactory');
require('./container/ContainerFactory');
require('./image/ImageFactory');
require('./sprite/SpriteFactory');
require('./blitter/BlitterFactory');
require('./text/BitmapTextFactory');
// require('./gameobjects/container/ContainerFactory');
// Phaser.GameObjects
module.exports = {
Factory: require('./FactoryContainer'),
Blitter: require('./blitter/Blitter'),
Container: require('./container/Container'),
Image: require('./image/Image'),
Sprite: require('./sprite/Sprite'),
Blitter: require('./blitter/Blitter')
Sprite: require('./sprite/Sprite')
};