var Class = require('../utils/Class'); var Components = require('./components'); var DataManager = require('../data/DataManager'); var EventEmitter = require('eventemitter3'); var GameObject = new Class({ Extends: EventEmitter, initialize: function GameObject(scene, type){ EventEmitter.call(this); this.scene = scene; this.type = type; this.name = ''; this.active = true ; this.tabIndex = -1; this.data = null ; this.renderFlags = 15; this.cameraFilter = 0; this.input = null ; this.body = null ; this.scene.sys.queueDepthSort(); } , setActive: function (value){ this.active = value; return this; } , setName: function (value){ this.name = value; return this; } , setDataEnabled: function (){ if (!this.data) { this.data = new DataManager(this); } return this; } , setData: function (key, value){ if (!this.data) { this.data = new DataManager(this); } this.data.set(key, value); return this; } , getData: function (key){ if (!this.data) { this.data = new DataManager(this); } return this.data.get(key); } , setInteractive: function (shape, callback, dropZone){ this.scene.sys.input.enable(this, shape, callback, dropZone); return this; } , update: function (){ } , toJSON: function (){ return Components.ToJSON(this); } , willRender: function (){ return (GameObject.RENDER_MASK === this.renderFlags); } , destroy: function (){ if (!this.scene) { return ; } if (this.preDestroy) { this.preDestroy.call(this); } var sys = this.scene.sys; sys.displayList.remove(this); sys.updateList.remove(this); if (this.input) { _AN_Call_clear('clear', sys.input, this); this.input = undefined; } if (this.data) { this.data.destroy(); this.data = undefined; } if (this.body) { this.body.destroy(); this.body = undefined; } sys.queueDepthSort(); this.active = false ; this.visible = false ; this.scene = undefined; this.emit('destroy'); this.removeAllListeners(); } } ); GameObject.RENDER_MASK = 15; module.exports = GameObject;