/// /** * Phaser - Basic * * A useful "generic" object on which all GameObjects and Groups are based. * It has no size, position or graphical data. */ module Phaser { export class Basic { /** * Instantiate the basic object. */ constructor(game: Game) { this._game = game; this.ID = -1; this.exists = true; this.active = true; this.visible = true; this.alive = true; this.isGroup = false; this.ignoreDrawDebug = false; } /** * The essential reference to the main game object */ public _game: Game; /** * Allows you to give this object a name. Useful for debugging, but not actually used internally. */ public name: string = ''; /** * IDs seem like they could be pretty useful, huh? * They're not actually used for anything yet though. */ public ID: number; /** * A boolean to store if this object is a Group or not. * Saves us an expensive typeof check inside of core loops. */ public isGroup: bool; /** * Controls whether update() and draw() are automatically called by State/Group. */ public exists: bool; /** * Controls whether update() is automatically called by State/Group. */ public active: bool; /** * Controls whether draw() is automatically called by State/Group. */ public visible: bool; /** * Useful state for many game objects - "dead" (!alive) vs alive. * kill() and revive() both flip this switch (along with exists, but you can override that). */ public alive: bool; /** * Setting this to true will prevent the object from appearing * when the visual debug mode in the debugger overlay is toggled on. */ public ignoreDrawDebug: bool; /** * Override this to null out iables or manually call * destroy() on class members if necessary. * Don't forget to call super.destroy()! */ public destroy() { } /** * Pre-update is called right before update() on each object in the game loop. */ public preUpdate() { } /** * Override this to update your class's position and appearance. * This is where most of your game rules and behavioral code will go. */ public update() { } /** * Post-update is called right after update() on each object in the game loop. */ public postUpdate() { } public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number) { } /** * Handy for "killing" game objects. * Default behavior is to flag them as nonexistent AND dead. * However, if you want the "corpse" to remain in the game, * like to animate an effect or whatever, you should override this, * setting only alive to false, and leaving exists true. */ public kill() { this.alive = false; this.exists = false; } /** * Handy for bringing game objects "back to life". Just sets alive and exists back to true. * In practice, this is most often called by Object.reset(). */ public revive() { this.alive = true; this.exists = true; } /** * Convert object to readable string name. Useful for debugging, save games, etc. */ public toString(): string { return ""; } } }