mirror of
https://github.com/photonstorm/phaser
synced 2024-12-18 00:53:42 +00:00
90 lines
2.1 KiB
JavaScript
90 lines
2.1 KiB
JavaScript
|
var GetAdvancedValue = require('../utils/object/GetAdvancedValue');
|
||
|
var ScaleModes = require('../renderer/ScaleModes');
|
||
|
var BlendModes = require('../renderer/BlendModes');
|
||
|
|
||
|
var BuildGameObject = function (state, gameObject, config)
|
||
|
{
|
||
|
// Position
|
||
|
|
||
|
gameObject.x = GetAdvancedValue(config, 'x', 0);
|
||
|
gameObject.y = GetAdvancedValue(config, 'y', 0);
|
||
|
gameObject.z = GetAdvancedValue(config, 'z', 0);
|
||
|
|
||
|
// Flip
|
||
|
|
||
|
gameObject.flipX = GetAdvancedValue(config, 'flipX', false);
|
||
|
gameObject.flipY = GetAdvancedValue(config, 'flipY', false);
|
||
|
|
||
|
// Scale
|
||
|
// Either: { scale: 2 } or { scale: { x: 2, y: 2 }}
|
||
|
|
||
|
var scale = GetAdvancedValue(config, 'scale', null);
|
||
|
|
||
|
if (typeof scale === 'number')
|
||
|
{
|
||
|
gameObject.setScale(scale);
|
||
|
}
|
||
|
else if (scale !== null)
|
||
|
{
|
||
|
gameObject.scaleX = GetAdvancedValue(scale, 'x', 1);
|
||
|
gameObject.scaleY = GetAdvancedValue(scale, 'y', 1);
|
||
|
}
|
||
|
|
||
|
// Rotation
|
||
|
|
||
|
gameObject.rotation = GetAdvancedValue(config, 'rotation', 0);
|
||
|
|
||
|
var angle = GetAdvancedValue(config, 'angle', null);
|
||
|
|
||
|
if (angle !== null)
|
||
|
{
|
||
|
gameObject.angle = angle;
|
||
|
}
|
||
|
|
||
|
// Alpha
|
||
|
|
||
|
gameObject.alpha = GetAdvancedValue(config, 'alpha', 1);
|
||
|
|
||
|
// Origin
|
||
|
// Either: { origin: 0.5 } or { origin: { x: 0.5, y: 0.5 }}
|
||
|
|
||
|
var origin = GetAdvancedValue(config, 'origin', null);
|
||
|
|
||
|
if (typeof origin === 'number')
|
||
|
{
|
||
|
gameObject.setOrigin(origin);
|
||
|
}
|
||
|
else if (origin !== null)
|
||
|
{
|
||
|
var ox = GetAdvancedValue(config, 'x', 0.5);
|
||
|
var oy = GetAdvancedValue(config, 'y', 0.5);
|
||
|
|
||
|
gameObject.setOrigin(ox, oy);
|
||
|
}
|
||
|
|
||
|
// ScaleMode
|
||
|
|
||
|
gameObject.scaleMode = GetAdvancedValue(config, 'scaleMode', ScaleModes.DEFAULT);
|
||
|
|
||
|
// BlendMode
|
||
|
|
||
|
gameObject.blendMode = GetAdvancedValue(config, 'blendMode', BlendModes.NORMAL);
|
||
|
|
||
|
// Visible
|
||
|
|
||
|
gameObject.visible = GetAdvancedValue(config, 'visible', true);
|
||
|
|
||
|
// Add to State
|
||
|
|
||
|
var add = GetAdvancedValue(config, 'add', true);
|
||
|
|
||
|
if (add)
|
||
|
{
|
||
|
state.children.add(gameObject);
|
||
|
}
|
||
|
|
||
|
return gameObject;
|
||
|
};
|
||
|
|
||
|
module.exports = BuildGameObject;
|