phaser/v3/src/gameobjects/GameObject.js

87 lines
1.8 KiB
JavaScript
Raw Normal View History

2016-12-07 02:28:22 +00:00
/**
* @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 MATH_CONST = require('../math/const');
2017-02-22 16:30:53 +00:00
var BlendModes = require('../renderer/BlendModes');
2017-01-18 14:48:02 +00:00
var ScaleModes = require('../renderer/ScaleModes');
var WrapAngle = require('../math/angle/Wrap');
2016-12-07 02:28:22 +00:00
/**
* This is the base Game Object class that you can use when creating your own extended Game Objects.
*
* @class
*/
2017-02-22 16:30:53 +00:00
// Texture is globally shared between GameObjects, not specific to this one
// Frame is globally shared between GameObjects, not specific to this one
2016-12-07 02:28:22 +00:00
2017-02-22 16:30:53 +00:00
var GameObject = function (state, x, y, texture, frame)
2016-12-07 02:28:22 +00:00
{
this.state = state;
this.game = state.sys.game;
2016-12-07 02:28:22 +00:00
this.name = '';
this.parent;
2016-12-07 02:28:22 +00:00
this.texture = texture;
this.frame = frame;
2017-02-22 16:30:53 +00:00
this.x = x;
this.y = y;
this.z = 0;
this.scaleX = 1;
this.scaleY = 1;
this.rotation = 0;
this.anchorX = 0;
this.anchorY = 0;
this.alpha = 1;
this.blendMode = BlendModes.NORMAL;
2017-01-18 14:48:02 +00:00
this.scaleMode = ScaleModes.DEFAULT;
2016-12-07 02:28:22 +00:00
this.visible = true;
};
GameObject.prototype.constructor = GameObject;
GameObject.prototype = {
destroy: function ()
{
2017-02-22 16:30:53 +00:00
this.state = undefined;
this.game = undefined;
this.texture = undefined;
this.frame = undefined;
2016-12-07 02:28:22 +00:00
}
};
Object.defineProperties(GameObject.prototype, {
angle: {
2016-12-07 02:28:22 +00:00
enumerable: true,
get: function ()
{
2017-02-22 16:30:53 +00:00
return WrapAngle(this.rotation * MATH_CONST.RAD_TO_DEG);
2016-12-07 02:28:22 +00:00
},
set: function (value)
{
// value is in degrees
2017-02-22 16:30:53 +00:00
this.rotation = WrapAngle(value * MATH_CONST.DEG_TO_RAD);
2016-12-07 02:28:22 +00:00
}
}
});
module.exports = GameObject;