var Class = require('../utils/Class'); var ComponentsToJSON = require('./components/ToJSON'); var DataManager = require('../data/DataManager'); var EventEmitter = require('eventemitter3'); var Events = require('./events'); var GameObject = new Class({ Extends: EventEmitter, initialize: function GameObject(scene, type){ EventEmitter.call(this); this.scene = scene; this.displayList = null ; this.type = type; this.state = 0; this.parentContainer = null ; this.name = ''; this.active = true ; this.tabIndex = -1; this.data = null ; this.renderFlags = 15; this.cameraFilter = 0; this.input = null ; this.body = null ; this.ignoreDestroy = false ; this.on(Events.ADDED_TO_SCENE, this.addedToScene, this); this.on(Events.REMOVED_FROM_SCENE, this.removedFromScene, this); scene.sys.queueDepthSort(); } , setActive: function (value){ this.active = value; return this; } , setName: function (value){ this.name = value; return this; } , setState: function (value){ this.state = 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; } , incData: function (key, value){ if (!this.data) { this.data = new DataManager(this); } this.data.inc(key, value); return this; } , toggleData: function (key){ if (!this.data) { this.data = new DataManager(this); } this.data.toggle(key); return this; } , getData: function (key){ if (!this.data) { this.data = new DataManager(this); } return this.data.get(key); } , setInteractive: function (hitArea, hitAreaCallback, dropZone){ this.scene.sys.input.enable(this, hitArea, hitAreaCallback, dropZone); return this; } , disableInteractive: function (){ if (this.input) { this.input.enabled = false ; } return this; } , removeInteractive: function (){ _AN_Call_clear('clear', this.scene.sys.input, this); this.input = undefined; return this; } , addedToScene: function (){ } , removedFromScene: function (){ } , update: function (){ } , toJSON: function (){ return ComponentsToJSON(this); } , willRender: function (camera){ return !(GameObject.RENDER_MASK !== this.renderFlags || (this.cameraFilter !== 0 && (this.cameraFilter & camera.id))); } , getIndexList: function (){ var child = this; var parent = this.parentContainer; var indexes = [] ; while (parent){ indexes.unshift(parent.getIndex(child)); child = parent; if (!parent.parentContainer) { break ; } else { parent = parent.parentContainer; } } if (this.displayList) { indexes.unshift(this.displayList.getIndex(child)); } else { indexes.unshift(this.scene.sys.displayList.getIndex(child)); } return indexes; } , destroy: function (){ if (!this.scene || this.ignoreDestroy) { return ; } if (this.preDestroy) { this.preDestroy.call(this); } this.emit(Events.DESTROY, this); this.removeAllListeners(); if (this.postPipelines) { this.resetPostPipeline(true ); } if (this.displayList) { this.displayList.queueDepthSort(); this.displayList.remove(this); } if (this.input) { _AN_Call_clear('clear', this.scene.sys.input, this); this.input = undefined; } if (this.data) { this.data.destroy(); this.data = undefined; } if (this.body) { this.body.destroy(); this.body = undefined; } this.active = false ; this.visible = false ; this.scene = undefined; this.displayList = undefined; this.parentContainer = undefined; } } ); GameObject.RENDER_MASK = 15; module.exports = GameObject;