Skip to content

Commit

Permalink
New v0.9.3 release - see the changelog in the README for full details.
Browse files Browse the repository at this point in the history
  • Loading branch information
photonstorm committed Apr 24, 2013
1 parent 1b6fbc1 commit 3898faf
Show file tree
Hide file tree
Showing 18 changed files with 378 additions and 76 deletions.
27 changes: 15 additions & 12 deletions Phaser/CameraManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ module Phaser {
}

private _game: Game;

private _cameras: Camera[];
private _cameraInstance: number = 0;

public current: Camera;

Expand All @@ -45,32 +45,35 @@ module Phaser {

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

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

this._cameras.push(newCam);

this._cameraInstance++;

return newCam;

}

public removeCamera(id: number): bool {

if (this._cameras[id])
for (var c = 0; c < this._cameras.length; c++)
{
if (this.current === this._cameras[id])
if (this._cameras[c].ID == id)
{
this.current = null;
}
if (this.current.ID === this._cameras[c].ID)
{
this.current = null;
}

this._cameras.splice(id, 1);
this._cameras.splice(c, 1);

return true;
}
else
{
return false;
return true;
}
}

return false;

}

public destroy() {
Expand Down
2 changes: 1 addition & 1 deletion Phaser/Phaser.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Phaser
*
* v0.9.3 - April 22nd 2013
* v0.9.3 - April 24th 2013
*
* A small and feature-packed 2D canvas game framework born from the firey pits of Flixel and Kiwi.
*
Expand Down
79 changes: 78 additions & 1 deletion Phaser/gameobjects/GameObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module Phaser {
this.health = 1;
this.immovable = false;
this.moves = true;
this.worldBounds = null;

this.touching = Collision.NONE;
this.wasTouching = Collision.NONE;
Expand All @@ -50,6 +51,7 @@ module Phaser {
this.angularDrag = 0;
this.maxAngular = 10000;

this.cameraBlacklist = [];
this.scrollFactor = new MicroPoint(1.0, 1.0);

}
Expand All @@ -66,9 +68,15 @@ module Phaser {
public static ALIGN_BOTTOM_CENTER: number = 7;
public static ALIGN_BOTTOM_RIGHT: number = 8;

public static OUT_OF_BOUNDS_STOP: number = 0;
public static OUT_OF_BOUNDS_KILL: number = 1;

public _point: MicroPoint;

public cameraBlacklist: number[];
public bounds: Rectangle;
public worldBounds: Quad;
public outOfBoundsAction: number = 0;
public align: number;
public facing: number;
public alpha: number;
Expand Down Expand Up @@ -136,6 +144,37 @@ module Phaser {
this.updateMotion();
}

if (this.worldBounds != null)
{
if (this.outOfBoundsAction == GameObject.OUT_OF_BOUNDS_KILL)
{
if (this.x < this.worldBounds.x || this.x > this.worldBounds.right || this.y < this.worldBounds.y || this.y > this.worldBounds.bottom)
{
this.kill();
}
}
else
{
if (this.x < this.worldBounds.x)
{
this.x = this.worldBounds.x;
}
else if (this.x > this.worldBounds.right)
{
this.x = this.worldBounds.right;
}

if (this.y < this.worldBounds.y)
{
this.y = this.worldBounds.y;
}
else if (this.y > this.worldBounds.bottom)
{
this.y = this.worldBounds.bottom;
}
}
}

if (this.inputEnabled)
{
this.updateInput();
Expand Down Expand Up @@ -175,7 +214,7 @@ module Phaser {

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

}

/**
* Set the world bounds that this GameObject can exist within. By default a GameObject can exist anywhere
* in the world. But by setting the bounds (which are given in world dimensions, not screen dimensions)
* it can be stopped from leaving the world, or a section of it.
*/
public setBounds(x: number, y: number, width: number, height: number) {

this.worldBounds = new Quad(x, y, width, height);

}

/**
* If you do not wish this object to be visible to a specific camera, pass the camera here.
*/
public hideFromCamera(camera: Camera) {

if (this.cameraBlacklist.indexOf(camera.ID) == -1)
{
this.cameraBlacklist.push(camera.ID);
}

}

public showToCamera(camera: Camera) {

if (this.cameraBlacklist.indexOf(camera.ID) !== -1)
{
this.cameraBlacklist.slice(this.cameraBlacklist.indexOf(camera.ID), 1);
}

}

public clearCameraList() {

this.cameraBlacklist.length = 0;

}

public destroy() {

}
Expand Down
2 changes: 1 addition & 1 deletion Phaser/gameobjects/GeomSprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ module Phaser {
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number): bool {

// Render checks
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)
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)
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion Phaser/gameobjects/ScrollZone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ module Phaser {
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number) {

// Render checks
if (this.visible === false || this.scale.x == 0 || this.scale.y == 0 || this.alpha < 0.1 || this.inCamera(camera.worldView) == false)
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)
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion Phaser/gameobjects/Sprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ module Phaser {
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number): bool {

// Render checks
if (this.visible === false || this.scale.x == 0 || this.scale.y == 0 || this.alpha < 0.1 || this.inCamera(camera.worldView) == false)
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)
{
return false;
}
Expand Down
9 changes: 6 additions & 3 deletions Phaser/gameobjects/Tilemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,13 @@ module Phaser {

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

// Loop through the layers
for (var i = 0; i < this._layers.length; i++)
if (this.cameraBlacklist.indexOf(camera.ID) == -1)
{
this._layers[i].render(camera, cameraOffsetX, cameraOffsetY);
// Loop through the layers
for (var i = 0; i < this._layers.length; i++)
{
this._layers[i].render(camera, cameraOffsetX, cameraOffsetY);
}
}

}
Expand Down
2 changes: 1 addition & 1 deletion Phaser/system/Camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ module Phaser {

public render() {

if (this.visible === false && this.alpha < 0.1)
if (this.visible === false || this.alpha < 0.1)
{
return;
}
Expand Down
7 changes: 3 additions & 4 deletions Phaser/system/TilemapLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ module Phaser {
//this.scrollFactor = new MicroPoint(1, 1);

this.mapData = [];

this._texture = this._game.cache.getImage(key);

this.parseTileOffsets();
Expand Down Expand Up @@ -197,9 +196,9 @@ module Phaser {
if (this._tileOffsets[this._columnData[tile]])
{
this._game.stage.context.drawImage(
this._texture, // Source Image
this._tileOffsets[this._columnData[tile]].x, // Source X (location within the source image)
this._tileOffsets[this._columnData[tile]].y, // Source Y
this._texture, // Source Image
this._tileOffsets[this._columnData[tile]].x, // Source X (location within the source image)
this._tileOffsets[this._columnData[tile]].y, // Source Y
this.tileWidth, // Source Width
this.tileHeight, // Source Height
this._tx, // Destination X (where on the canvas it'll be drawn)
Expand Down
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,21 @@ Change Log

V0.9.3

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

V0.9.2

Expand Down
4 changes: 4 additions & 0 deletions Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@
<Content Include="sprites\flipped.js">
<DependentUpon>flipped.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="tilemap\small map.ts" />
<Content Include="tilemap\small map.js">
<DependentUpon>small map.ts</DependentUpon>
</Content>
<Content Include="tweens\bounce.js">
<DependentUpon>bounce.ts</DependentUpon>
</Content>
Expand Down
Loading

0 comments on commit 3898faf

Please sign in to comment.