/// /** * Phaser */ module Phaser { export class World { constructor(game: Game, width: number, height: number) { this._game = game; this._cameras = new Cameras(this._game, 0, 0, width, height); this._game.camera = this._cameras.current; this.group = new Group(this._game, 0); this.bounds = new Rectangle(0, 0, width, height); this.worldDivisions = 6; } private _game: Game; private _cameras: Cameras; public group: Group; public bounds: Rectangle; public worldDivisions: number; public update() { this.group.preUpdate(); this.group.update(); this.group.postUpdate(); this._cameras.update(); } public render() { // Unlike in flixel our render process is camera driven, not group driven this._cameras.render(); } public destroy() { this.group.destroy(); this._cameras.destroy(); } // World methods public setSize(width: number, height: number, updateCameraBounds: bool = true) { this.bounds.width = width; this.bounds.height = height; if (updateCameraBounds == true) { this._game.camera.setBounds(0, 0, width, height); } } public get width(): number { return this.bounds.width; } public set width(value: number) { this.bounds.width = value; } public get height(): number { return this.bounds.height; } public set height(value: number) { this.bounds.height = value; } public get centerX(): number { return this.bounds.halfWidth; } public get centerY(): number { return this.bounds.halfHeight; } public get randomX(): number { return Math.round(Math.random() * this.bounds.width); } public get randomY(): number { return Math.round(Math.random() * this.bounds.height); } // Cameras public addExistingCamera(cam: Camera): Camera { //return this._cameras.addCamera(x, y, width, height); return cam; } public createCamera(x: number, y: number, width: number, height: number): Camera { return this._cameras.addCamera(x, y, width, height); } public removeCamera(id: number): bool { return this._cameras.removeCamera(id); } public getAllCameras(): Camera[] { return this._cameras.getAll(); } // Sprites // Drop this? public addExistingSprite(sprite: Sprite): Sprite { return this.group.add(sprite); } public createSprite(x: number, y: number, key?: string = ''): Sprite { return this.group.add(new Sprite(this._game, x, y, key)); } public createGeomSprite(x: number, y: number): GeomSprite { return this.group.add(new GeomSprite(this._game, x, y)); } public createDynamicTexture(key: string, width: number, height: number): DynamicTexture { return new DynamicTexture(this._game, key, width, height); } public createGroup(MaxSize?: number = 0): Group { return this.group.add(new Group(this._game, MaxSize)); } // Tilemaps public createTilemap(key: string, mapData: string, format: number, tileWidth?: number, tileHeight?: number): Tilemap { return this.group.add(new Tilemap(this._game, key, mapData, format, tileWidth, tileHeight)); } // Emitters public createParticle(): Particle { return new Particle(this._game); } public createEmitter(x?: number = 0, y?: number = 0, size?: number = 0): Emitter { return this.group.add(new Emitter(this._game, x, y, size)); } } }