Skip to content

Commit 3898faf

Browse files
committed
New v0.9.3 release - see the changelog in the README for full details.
1 parent 1b6fbc1 commit 3898faf

18 files changed

Lines changed: 378 additions & 76 deletions

Phaser/CameraManager.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ module Phaser {
2626
}
2727

2828
private _game: Game;
29-
3029
private _cameras: Camera[];
30+
private _cameraInstance: number = 0;
3131

3232
public current: Camera;
3333

@@ -45,32 +45,35 @@ module Phaser {
4545

4646
public addCamera(x: number, y: number, width: number, height: number): Camera {
4747

48-
var newCam: Camera = new Camera(this._game, this._cameras.length, x, y, width, height);
48+
var newCam: Camera = new Camera(this._game, this._cameraInstance, x, y, width, height);
4949

5050
this._cameras.push(newCam);
5151

52+
this._cameraInstance++;
53+
5254
return newCam;
5355

5456
}
5557

5658
public removeCamera(id: number): bool {
5759

58-
if (this._cameras[id])
60+
for (var c = 0; c < this._cameras.length; c++)
5961
{
60-
if (this.current === this._cameras[id])
62+
if (this._cameras[c].ID == id)
6163
{
62-
this.current = null;
63-
}
64+
if (this.current.ID === this._cameras[c].ID)
65+
{
66+
this.current = null;
67+
}
6468

65-
this._cameras.splice(id, 1);
69+
this._cameras.splice(c, 1);
6670

67-
return true;
68-
}
69-
else
70-
{
71-
return false;
71+
return true;
72+
}
7273
}
7374

75+
return false;
76+
7477
}
7578

7679
public destroy() {

Phaser/Phaser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Phaser
33
*
4-
* v0.9.3 - April 22nd 2013
4+
* v0.9.3 - April 24th 2013
55
*
66
* A small and feature-packed 2D canvas game framework born from the firey pits of Flixel and Kiwi.
77
*

Phaser/gameobjects/GameObject.ts

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ module Phaser {
3434
this.health = 1;
3535
this.immovable = false;
3636
this.moves = true;
37+
this.worldBounds = null;
3738

3839
this.touching = Collision.NONE;
3940
this.wasTouching = Collision.NONE;
@@ -50,6 +51,7 @@ module Phaser {
5051
this.angularDrag = 0;
5152
this.maxAngular = 10000;
5253

54+
this.cameraBlacklist = [];
5355
this.scrollFactor = new MicroPoint(1.0, 1.0);
5456

5557
}
@@ -66,9 +68,15 @@ module Phaser {
6668
public static ALIGN_BOTTOM_CENTER: number = 7;
6769
public static ALIGN_BOTTOM_RIGHT: number = 8;
6870

71+
public static OUT_OF_BOUNDS_STOP: number = 0;
72+
public static OUT_OF_BOUNDS_KILL: number = 1;
73+
6974
public _point: MicroPoint;
7075

76+
public cameraBlacklist: number[];
7177
public bounds: Rectangle;
78+
public worldBounds: Quad;
79+
public outOfBoundsAction: number = 0;
7280
public align: number;
7381
public facing: number;
7482
public alpha: number;
@@ -136,6 +144,37 @@ module Phaser {
136144
this.updateMotion();
137145
}
138146

147+
if (this.worldBounds != null)
148+
{
149+
if (this.outOfBoundsAction == GameObject.OUT_OF_BOUNDS_KILL)
150+
{
151+
if (this.x < this.worldBounds.x || this.x > this.worldBounds.right || this.y < this.worldBounds.y || this.y > this.worldBounds.bottom)
152+
{
153+
this.kill();
154+
}
155+
}
156+
else
157+
{
158+
if (this.x < this.worldBounds.x)
159+
{
160+
this.x = this.worldBounds.x;
161+
}
162+
else if (this.x > this.worldBounds.right)
163+
{
164+
this.x = this.worldBounds.right;
165+
}
166+
167+
if (this.y < this.worldBounds.y)
168+
{
169+
this.y = this.worldBounds.y;
170+
}
171+
else if (this.y > this.worldBounds.bottom)
172+
{
173+
this.y = this.worldBounds.bottom;
174+
}
175+
}
176+
}
177+
139178
if (this.inputEnabled)
140179
{
141180
this.updateInput();
@@ -175,7 +214,7 @@ module Phaser {
175214

176215
/**
177216
* Checks to see if some <code>GameObject</code> overlaps this <code>GameObject</code> or <code>Group</code>.
178-
* If the group has a LOT of things in it, it might be faster to use <code>G.overlaps()</code>.
217+
* If the group has a LOT of things in it, it might be faster to use <code>Collision.overlaps()</code>.
179218
* WARNING: Currently tilemaps do NOT support screen space overlap checks!
180219
*
181220
* @param ObjectOrGroup The object or group being tested.
@@ -489,6 +528,44 @@ module Phaser {
489528

490529
}
491530

531+
/**
532+
* Set the world bounds that this GameObject can exist within. By default a GameObject can exist anywhere
533+
* in the world. But by setting the bounds (which are given in world dimensions, not screen dimensions)
534+
* it can be stopped from leaving the world, or a section of it.
535+
*/
536+
public setBounds(x: number, y: number, width: number, height: number) {
537+
538+
this.worldBounds = new Quad(x, y, width, height);
539+
540+
}
541+
542+
/**
543+
* If you do not wish this object to be visible to a specific camera, pass the camera here.
544+
*/
545+
public hideFromCamera(camera: Camera) {
546+
547+
if (this.cameraBlacklist.indexOf(camera.ID) == -1)
548+
{
549+
this.cameraBlacklist.push(camera.ID);
550+
}
551+
552+
}
553+
554+
public showToCamera(camera: Camera) {
555+
556+
if (this.cameraBlacklist.indexOf(camera.ID) !== -1)
557+
{
558+
this.cameraBlacklist.slice(this.cameraBlacklist.indexOf(camera.ID), 1);
559+
}
560+
561+
}
562+
563+
public clearCameraList() {
564+
565+
this.cameraBlacklist.length = 0;
566+
567+
}
568+
492569
public destroy() {
493570

494571
}

Phaser/gameobjects/GeomSprite.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ module Phaser {
190190
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number): bool {
191191

192192
// Render checks
193-
if (this.type == GeomSprite.UNASSIGNED || this.visible === false || this.scale.x == 0 || this.scale.y == 0 || this.alpha < 0.1 || this.inCamera(camera.worldView) == false)
193+
if (this.type == GeomSprite.UNASSIGNED || this.visible === false || this.scale.x == 0 || this.scale.y == 0 || this.alpha < 0.1 || this.cameraBlacklist.indexOf(camera.ID) !== -1 || this.inCamera(camera.worldView) == false)
194194
{
195195
return false;
196196
}

Phaser/gameobjects/ScrollZone.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ module Phaser {
119119
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number) {
120120

121121
// Render checks
122-
if (this.visible === false || this.scale.x == 0 || this.scale.y == 0 || this.alpha < 0.1 || this.inCamera(camera.worldView) == false)
122+
if (this.visible == false || this.scale.x == 0 || this.scale.y == 0 || this.alpha < 0.1 || this.cameraBlacklist.indexOf(camera.ID) !== -1 || this.inCamera(camera.worldView) == false)
123123
{
124124
return false;
125125
}

Phaser/gameobjects/Sprite.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ module Phaser {
146146
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number): bool {
147147

148148
// Render checks
149-
if (this.visible === false || this.scale.x == 0 || this.scale.y == 0 || this.alpha < 0.1 || this.inCamera(camera.worldView) == false)
149+
if (this.visible == false || this.scale.x == 0 || this.scale.y == 0 || this.alpha < 0.1 || this.cameraBlacklist.indexOf(camera.ID) !== -1 || this.inCamera(camera.worldView) == false)
150150
{
151151
return false;
152152
}

Phaser/gameobjects/Tilemap.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,13 @@ module Phaser {
5454

5555
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number) {
5656

57-
// Loop through the layers
58-
for (var i = 0; i < this._layers.length; i++)
57+
if (this.cameraBlacklist.indexOf(camera.ID) == -1)
5958
{
60-
this._layers[i].render(camera, cameraOffsetX, cameraOffsetY);
59+
// Loop through the layers
60+
for (var i = 0; i < this._layers.length; i++)
61+
{
62+
this._layers[i].render(camera, cameraOffsetX, cameraOffsetY);
63+
}
6164
}
6265

6366
}

Phaser/system/Camera.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ module Phaser {
439439

440440
public render() {
441441

442-
if (this.visible === false && this.alpha < 0.1)
442+
if (this.visible === false || this.alpha < 0.1)
443443
{
444444
return;
445445
}

Phaser/system/TilemapLayer.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ module Phaser {
2222
//this.scrollFactor = new MicroPoint(1, 1);
2323

2424
this.mapData = [];
25-
2625
this._texture = this._game.cache.getImage(key);
2726

2827
this.parseTileOffsets();
@@ -197,9 +196,9 @@ module Phaser {
197196
if (this._tileOffsets[this._columnData[tile]])
198197
{
199198
this._game.stage.context.drawImage(
200-
this._texture, // Source Image
201-
this._tileOffsets[this._columnData[tile]].x, // Source X (location within the source image)
202-
this._tileOffsets[this._columnData[tile]].y, // Source Y
199+
this._texture, // Source Image
200+
this._tileOffsets[this._columnData[tile]].x, // Source X (location within the source image)
201+
this._tileOffsets[this._columnData[tile]].y, // Source Y
203202
this.tileWidth, // Source Width
204203
this.tileHeight, // Source Height
205204
this._tx, // Destination X (where on the canvas it'll be drawn)

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,21 @@ Change Log
2020

2121
V0.9.3
2222

23-
* Fixed issues with Group not adding reference to Game to newly created objects.
23+
* Added the new ScrollZone game object. Endlessly useful but especially for scrolling backdrops. Created 6 example tests.
24+
* Added GameObject.hideFromCamera(cameraID) to stop an object rendering to specific cameras (also showToCamera and clearCameraList)
25+
* Added GameObject.setBounds() to confine a game object to a specific area within the world (useful for stopping them going off the edges)
26+
* Added GameObject.outOfBoundsAction, can be either OUT OF BOUNDS STOP which stops the object moving, or OUT OF BOUNDS KILL which kills it.
27+
* Added GameObject.rotationOffset. Useful if your graphics need to rotate but weren't drawn facing zero degrees (to the right).
28+
* Added shiftSinTable and shiftCosTable to the GameMath class to allow for quick iteration through the data tables.
2429
* Added more robust frame checking into AnimationManager
2530
* Re-built Tilemap handling from scratch to allow for proper layered maps (as exported from Tiled / Mappy)
2631
* Tilemap no longer requires a buffer per Camera (in prep for WebGL support)
27-
* Added shiftSinTable and shiftCosTable to the GameMath class to allow for quick iteration through the data tables.
28-
* Added the new ScrollZone game object. Endlessly useful but especially for scrolling backdrops. Created 6 example tests.
29-
* Removed the need for DynamicTextures to require a key property and updated test cases.
30-
* Add the rotationOffset value to GameObject (and thus Sprite). Useful if your graphics need to rotate but weren't drawn facing zero degrees (to the right).
31-
* You can now pass an array or a single value to Input.Keyboard.addKeyCapture()
32+
* Fixed issues with Group not adding reference to Game to newly created objects (thanks JesseFreeman)
3233
* Fixed a potential race condition issue in Game.boot (thanks Hackmaniac)
3334
* Fixed issue with showing frame zero of a texture atlas before the animation started playing (thanks JesseFreeman)
35+
* Fixed a bug where Camera.visible = false would still render
36+
* Removed the need for DynamicTextures to require a key property and updated test cases.
37+
* You can now pass an array or a single value to Input.Keyboard.addKeyCapture().
3438

3539
V0.9.2
3640

0 commit comments

Comments
 (0)