var MATH_CONST = require('../math/const'); var ScaleModes = require('../renderer/ScaleModes'); var Component = require('../components'); var WrapAngle = require('../math/angle/Wrap'); var GameObject = function (state, x, y, texture, frame, parent){ this.state = state; this.game = state.sys.game; this.name = ''; this.type = 0; this.parent = parent; this.texture = texture; this.frame = frame; this.transform = new Component.Transform(this, this.state.sys.transform); this.transform.positionX = x; this.transform.positionY = y; this.anchor = new Component.Anchor(); this.data = new Component.Data(this); this.color = new Component.Color(this); this.scaleMode = ScaleModes.DEFAULT; this.skipRender = false ; this.visible = true ; this.children = null ; this.exists = true ; } ; GameObject.prototype.constructor = GameObject; GameObject.prototype = { preUpdate: function (){ } , update: function (){ } , postUpdate: function (){ } , render: function (){ } , destroy: function (){ } } ; Object.defineProperties(GameObject.prototype, { x: { enumerable: true , get: function (){ return this.transform.positionX; } , set: function (value){ this.transform.positionX = value; this.transform.dirtyLocal = true ; } } , y: { enumerable: true , get: function (){ return this.transform.positionY; } , set: function (value){ this.transform.positionY = value; this.transform.dirtyLocal = true ; } } , scale: { enumerable: true , get: function (){ return this.transform.scaleX; } , set: function (value){ this.transform.scaleX = value; this.transform.scaleY = value; this.transform.dirtyLocal = true ; } } , scaleX: { enumerable: true , get: function (){ return this.transform.scaleX; } , set: function (value){ this.transform.scaleX = value; this.transform.dirtyLocal = true ; } } , scaleY: { enumerable: true , get: function (){ return this.transform.scaleY; } , set: function (value){ this.transform.scaleY = value; this.transform.dirtyLocal = true ; } } , rotation: { enumerable: true , get: function (){ return this.transform.rotation; } , set: function (value){ this.transform.rotation = value; this.transform.dirtyLocal = true ; } } , angle: { enumerable: true , get: function (){ return WrapAngle(this.transform.rotation * MATH_CONST.RAD_TO_DEG); } , set: function (value){ this.transform.rotation = WrapAngle(value * MATH_CONST.DEG_TO_RAD); this.transform.dirtyLocal = true ; } } , anchorX: { enumerable: true , get: function (){ return this.anchor.getX(); } , set: function (value){ this.anchor.setX(value); } } , anchorY: { enumerable: true , get: function (){ return this.anchor.getY(); } , set: function (value){ this.anchor.setY(value); } } , alpha: { enumerable: true , get: function (){ return this.color._alpha; } , set: function (value){ this.color.alpha = value; } } , blendMode: { enumerable: true , get: function (){ return this.color._blendMode; } , set: function (value){ this.color.blendMode = value; } } } ); module.exports = GameObject;