New v0.9.3 release - see the changelog in the README for full details.

This commit is contained in:
Richard Davey committed 2013-04-24 02:48:03 +01:00
1 parent 1b6fbc1324
commit 3898faf17e
18 files changed
+379 -77

No files matched your search

+16 -13
View File
@@ -26,8 +26,8 @@ module Phaser {
}
private _game: Game;
private _cameras: Camera[];
private _cameraInstance: number = 0;
public current: Camera;
@@ -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(c, 1);
return true;
}
this._cameras.splice(id, 1);
return true;
}
else
{
return false;
}
return false;
}
public destroy() {
+1 -1
View File
@@ -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.
*
+78 -1
View File
@@ -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;
@@ -50,6 +51,7 @@ module Phaser {
this.angularDrag = 0;
this.maxAngular = 10000;
this.cameraBlacklist = [];
this.scrollFactor = new MicroPoint(1.0, 1.0);
}
@@ -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;
@@ -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();
@@ -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.
@@ -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() {
}
+1 -1
View File
@@ -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;
}
+1 -1
View File
@@ -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;
}
+1 -1
View File
@@ -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;
}
+6 -3
View File
@@ -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);
}
}
}
+1 -1
View File
@@ -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;
}
+3 -4
View File
@@ -22,7 +22,6 @@ module Phaser {
//this.scrollFactor = new MicroPoint(1, 1);
this.mapData = [];
this._texture = this._game.cache.getImage(key);
this.parseTileOffsets();
@@ -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)
+10 -6
View File
@@ -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
+4
View File
@@ -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>
+72 -20
View File
@@ -466,6 +466,7 @@ var Phaser;
if (typeof height === "undefined") { height = 16; }
_super.call(this, game);
this._angle = 0;
this.outOfBoundsAction = 0;
this.z = 0;
// This value is added to the angle of the GameObject.
// For example if you had a sprite drawn facing straight up then you could set
@@ -491,6 +492,7 @@ var Phaser;
this.health = 1;
this.immovable = false;
this.moves = true;
this.worldBounds = null;
this.touching = Phaser.Collision.NONE;
this.wasTouching = Phaser.Collision.NONE;
this.allowCollisions = Phaser.Collision.ANY;
@@ -503,6 +505,7 @@ var Phaser;
this.angularAcceleration = 0;
this.angularDrag = 0;
this.maxAngular = 10000;
this.cameraBlacklist = [];
this.scrollFactor = new Phaser.MicroPoint(1.0, 1.0);
}
GameObject.ALIGN_TOP_LEFT = 0;
@@ -514,6 +517,8 @@ var Phaser;
GameObject.ALIGN_BOTTOM_LEFT = 6;
GameObject.ALIGN_BOTTOM_CENTER = 7;
GameObject.ALIGN_BOTTOM_RIGHT = 8;
GameObject.OUT_OF_BOUNDS_STOP = 0;
GameObject.OUT_OF_BOUNDS_KILL = 1;
GameObject.prototype.preUpdate = function () {
// flicker time
this.last.x = this.bounds.x;
@@ -525,6 +530,24 @@ var Phaser;
if(this.moves) {
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();
}
@@ -553,7 +576,7 @@ var Phaser;
};
GameObject.prototype.overlaps = /**
* 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.
@@ -799,6 +822,30 @@ var Phaser;
this.kill();
}
};
GameObject.prototype.setBounds = /**
* 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.
*/
function (x, y, width, height) {
this.worldBounds = new Phaser.Quad(x, y, width, height);
};
GameObject.prototype.hideFromCamera = /**
* If you do not wish this object to be visible to a specific camera, pass the camera here.
*/
function (camera) {
if(this.cameraBlacklist.indexOf(camera.ID) == -1) {
this.cameraBlacklist.push(camera.ID);
}
};
GameObject.prototype.showToCamera = function (camera) {
if(this.cameraBlacklist.indexOf(camera.ID) !== -1) {
this.cameraBlacklist.slice(this.cameraBlacklist.indexOf(camera.ID), 1);
}
};
GameObject.prototype.clearCameraList = function () {
this.cameraBlacklist.length = 0;
};
GameObject.prototype.destroy = function () {
};
Object.defineProperty(GameObject.prototype, "x", {
@@ -1191,7 +1238,7 @@ var Phaser;
}
};
Camera.prototype.render = function () {
if(this.visible === false && this.alpha < 0.1) {
if(this.visible === false || this.alpha < 0.1) {
return;
}
if((this._fxShakeOffset.x != 0) || (this._fxShakeOffset.y != 0)) {
@@ -1494,7 +1541,7 @@ var Phaser;
});
Sprite.prototype.render = function (camera, cameraOffsetX, cameraOffsetY) {
// 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;
}
// Alpha
@@ -2216,6 +2263,7 @@ var Phaser;
(function (Phaser) {
var CameraManager = (function () {
function CameraManager(game, x, y, width, height) {
this._cameraInstance = 0;
this._game = game;
this._cameras = [];
this.current = this.addCamera(x, y, width, height);
@@ -2234,20 +2282,22 @@ var Phaser;
});
};
CameraManager.prototype.addCamera = function (x, y, width, height) {
var newCam = new Phaser.Camera(this._game, this._cameras.length, x, y, width, height);
var newCam = new Phaser.Camera(this._game, this._cameraInstance, x, y, width, height);
this._cameras.push(newCam);
this._cameraInstance++;
return newCam;
};
CameraManager.prototype.removeCamera = function (id) {
if(this._cameras[id]) {
if(this.current === this._cameras[id]) {
this.current = null;
for(var c = 0; c < this._cameras.length; c++) {
if(this._cameras[c].ID == id) {
if(this.current.ID === this._cameras[c].ID) {
this.current = null;
}
this._cameras.splice(c, 1);
return true;
}
this._cameras.splice(id, 1);
return true;
} else {
return false;
}
return false;
};
CameraManager.prototype.destroy = function () {
this._cameras.length = 0;
@@ -7415,7 +7465,7 @@ var Phaser;
/**
* 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.
*
@@ -10679,7 +10729,7 @@ var Phaser;
};
GeomSprite.prototype.render = function (camera, cameraOffsetX, cameraOffsetY) {
// 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;
}
// Alpha
@@ -11058,9 +11108,9 @@ var Phaser;
this._columnData = this.mapData[row];
for(var tile = this._startX; tile < this._startX + this._maxX; tile++) {
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._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.tileWidth, // Source Width
this.tileHeight, // Source Height
this._tx, // Destination X (where on the canvas it'll be drawn)
@@ -11121,9 +11171,11 @@ var Phaser;
Tilemap.prototype.update = function () {
};
Tilemap.prototype.render = function (camera, cameraOffsetX, cameraOffsetY) {
// Loop through the layers
for(var i = 0; i < this._layers.length; i++) {
this._layers[i].render(camera, cameraOffsetX, cameraOffsetY);
if(this.cameraBlacklist.indexOf(camera.ID) == -1) {
// Loop through the layers
for(var i = 0; i < this._layers.length; i++) {
this._layers[i].render(camera, cameraOffsetX, cameraOffsetY);
}
}
};
Tilemap.prototype.parseCSV = function (data, key, tileWidth, tileHeight) {
@@ -11806,7 +11858,7 @@ var Phaser;
};
ScrollZone.prototype.render = function (camera, cameraOffsetX, cameraOffsetY) {
// 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;
}
// Alpha
+2 -2
View File
@@ -27,6 +27,8 @@
var tempBullet = new Phaser.Sprite(myGame, myGame.stage.centerX, myGame.stage.centerY, 'bullet');
tempBullet.exists = false;
tempBullet.rotationOffset = 90;
tempBullet.setBounds(-100, -100, 900, 700);
tempBullet.outOfBoundsAction = Phaser.GameObject.OUT_OF_BOUNDS_KILL;
bullets.add(tempBullet);
}
ship = myGame.createSprite(myGame.stage.centerX, myGame.stage.centerY, 'nashwan');
@@ -34,8 +36,6 @@
ship.rotationOffset = 90;
}
function update() {
// Recycle bullets
bullets.forEach(recycleBullet);
ship.angularVelocity = 0;
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
ship.angularVelocity = -200;
+2 -3
View File
@@ -41,6 +41,8 @@
var tempBullet = new Phaser.Sprite(myGame, myGame.stage.centerX, myGame.stage.centerY, 'bullet');
tempBullet.exists = false;
tempBullet.rotationOffset = 90;
tempBullet.setBounds(-100, -100, 900, 700);
tempBullet.outOfBoundsAction = Phaser.GameObject.OUT_OF_BOUNDS_KILL;
bullets.add(tempBullet);
}
@@ -53,9 +55,6 @@
function update() {
// Recycle bullets
bullets.forEach(recycleBullet);
ship.angularVelocity = 0;
if (myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT))
+42
View File
@@ -0,0 +1,42 @@
/// <reference path="../../Phaser/gameobjects/Tilemap.ts" />
/// <reference path="../../Phaser/Game.ts" />
(function () {
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
function init() {
myGame.loader.addTextFile('jsontest', 'assets/maps/multi-layer-test.json');
myGame.loader.addImageFile('jsontiles', 'assets/tiles/platformer_tiles.png');
myGame.loader.addImageFile('overlay', 'assets/pics/scrollframe.png');
myGame.loader.addImageFile('car', 'assets/sprites/car90.png');
myGame.loader.load();
}
var car;
var map;
var overlay;
var smallCam;
function create() {
map = myGame.createTilemap('jsontiles', 'jsontest', Phaser.Tilemap.FORMAT_TILED_JSON);
car = myGame.createSprite(300, 100, 'car');
car.setBounds(0, 0, map.widthInPixels - 32, map.heightInPixels - 32);
// Hide the tilemap and car sprite from the main camera (it will still be seen by the smallCam)
map.hideFromCamera(myGame.camera);
car.hideFromCamera(myGame.camera);
smallCam = myGame.world.createCamera(32, 32, 352, 240);
smallCam.setBounds(0, 0, map.widthInPixels, map.heightInPixels);
smallCam.follow(car);
overlay = myGame.createSprite(0, 0, 'overlay');
overlay.hideFromCamera(smallCam);
}
function update() {
car.velocity.x = 0;
car.velocity.y = 0;
car.angularVelocity = 0;
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
car.angularVelocity = -200;
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
car.angularVelocity = 200;
}
if(myGame.input.keyboard.isDown(Phaser.Keyboard.UP)) {
car.velocity.copyFrom(myGame.motion.velocityFromAngle(car.angle, 300));
}
}
})();
+66
View File
@@ -0,0 +1,66 @@
/// <reference path="../../Phaser/gameobjects/Tilemap.ts" />
/// <reference path="../../Phaser/Game.ts" />
(function () {
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
function init() {
myGame.loader.addTextFile('jsontest', 'assets/maps/multi-layer-test.json');
myGame.loader.addImageFile('jsontiles', 'assets/tiles/platformer_tiles.png');
myGame.loader.addImageFile('overlay', 'assets/pics/scrollframe.png');
myGame.loader.addImageFile('car', 'assets/sprites/car90.png');
myGame.loader.load();
}
var car: Phaser.Sprite;
var map: Phaser.Tilemap;
var overlay: Phaser.Sprite;
var smallCam: Phaser.Camera;
function create() {
map = myGame.createTilemap('jsontiles', 'jsontest', Phaser.Tilemap.FORMAT_TILED_JSON);
car = myGame.createSprite(300, 100, 'car');
car.setBounds(0, 0, map.widthInPixels - 32, map.heightInPixels - 32);
// Hide the tilemap and car sprite from the main camera (it will still be seen by the smallCam)
map.hideFromCamera(myGame.camera);
car.hideFromCamera(myGame.camera);
smallCam = myGame.world.createCamera(32, 32, 352, 240);
smallCam.setBounds(0, 0, map.widthInPixels, map.heightInPixels);
smallCam.follow(car);
overlay = myGame.createSprite(0, 0, 'overlay');
overlay.hideFromCamera(smallCam);
}
function update() {
car.velocity.x = 0;
car.velocity.y = 0;
car.angularVelocity = 0;
if (myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
car.angularVelocity = -200;
}
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
car.angularVelocity = 200;
}
if (myGame.input.keyboard.isDown(Phaser.Keyboard.UP))
{
car.velocity.copyFrom(myGame.motion.velocityFromAngle(car.angle, 300));
}
}
})();
+72 -20
View File
@@ -466,6 +466,7 @@ var Phaser;
if (typeof height === "undefined") { height = 16; }
_super.call(this, game);
this._angle = 0;
this.outOfBoundsAction = 0;
this.z = 0;
// This value is added to the angle of the GameObject.
// For example if you had a sprite drawn facing straight up then you could set
@@ -491,6 +492,7 @@ var Phaser;
this.health = 1;
this.immovable = false;
this.moves = true;
this.worldBounds = null;
this.touching = Phaser.Collision.NONE;
this.wasTouching = Phaser.Collision.NONE;
this.allowCollisions = Phaser.Collision.ANY;
@@ -503,6 +505,7 @@ var Phaser;
this.angularAcceleration = 0;
this.angularDrag = 0;
this.maxAngular = 10000;
this.cameraBlacklist = [];
this.scrollFactor = new Phaser.MicroPoint(1.0, 1.0);
}
GameObject.ALIGN_TOP_LEFT = 0;
@@ -514,6 +517,8 @@ var Phaser;
GameObject.ALIGN_BOTTOM_LEFT = 6;
GameObject.ALIGN_BOTTOM_CENTER = 7;
GameObject.ALIGN_BOTTOM_RIGHT = 8;
GameObject.OUT_OF_BOUNDS_STOP = 0;
GameObject.OUT_OF_BOUNDS_KILL = 1;
GameObject.prototype.preUpdate = function () {
// flicker time
this.last.x = this.bounds.x;
@@ -525,6 +530,24 @@ var Phaser;
if(this.moves) {
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();
}
@@ -553,7 +576,7 @@ var Phaser;
};
GameObject.prototype.overlaps = /**
* 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.
@@ -799,6 +822,30 @@ var Phaser;
this.kill();
}
};
GameObject.prototype.setBounds = /**
* 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.
*/
function (x, y, width, height) {
this.worldBounds = new Phaser.Quad(x, y, width, height);
};
GameObject.prototype.hideFromCamera = /**
* If you do not wish this object to be visible to a specific camera, pass the camera here.
*/
function (camera) {
if(this.cameraBlacklist.indexOf(camera.ID) == -1) {
this.cameraBlacklist.push(camera.ID);
}
};
GameObject.prototype.showToCamera = function (camera) {
if(this.cameraBlacklist.indexOf(camera.ID) !== -1) {
this.cameraBlacklist.slice(this.cameraBlacklist.indexOf(camera.ID), 1);
}
};
GameObject.prototype.clearCameraList = function () {
this.cameraBlacklist.length = 0;
};
GameObject.prototype.destroy = function () {
};
Object.defineProperty(GameObject.prototype, "x", {
@@ -1191,7 +1238,7 @@ var Phaser;
}
};
Camera.prototype.render = function () {
if(this.visible === false && this.alpha < 0.1) {
if(this.visible === false || this.alpha < 0.1) {
return;
}
if((this._fxShakeOffset.x != 0) || (this._fxShakeOffset.y != 0)) {
@@ -1494,7 +1541,7 @@ var Phaser;
});
Sprite.prototype.render = function (camera, cameraOffsetX, cameraOffsetY) {
// 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;
}
// Alpha
@@ -2216,6 +2263,7 @@ var Phaser;
(function (Phaser) {
var CameraManager = (function () {
function CameraManager(game, x, y, width, height) {
this._cameraInstance = 0;
this._game = game;
this._cameras = [];
this.current = this.addCamera(x, y, width, height);
@@ -2234,20 +2282,22 @@ var Phaser;
});
};
CameraManager.prototype.addCamera = function (x, y, width, height) {
var newCam = new Phaser.Camera(this._game, this._cameras.length, x, y, width, height);
var newCam = new Phaser.Camera(this._game, this._cameraInstance, x, y, width, height);
this._cameras.push(newCam);
this._cameraInstance++;
return newCam;
};
CameraManager.prototype.removeCamera = function (id) {
if(this._cameras[id]) {
if(this.current === this._cameras[id]) {
this.current = null;
for(var c = 0; c < this._cameras.length; c++) {
if(this._cameras[c].ID == id) {
if(this.current.ID === this._cameras[c].ID) {
this.current = null;
}
this._cameras.splice(c, 1);
return true;
}
this._cameras.splice(id, 1);
return true;
} else {
return false;
}
return false;
};
CameraManager.prototype.destroy = function () {
this._cameras.length = 0;
@@ -7415,7 +7465,7 @@ var Phaser;
/**
* 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.
*
@@ -10679,7 +10729,7 @@ var Phaser;
};
GeomSprite.prototype.render = function (camera, cameraOffsetX, cameraOffsetY) {
// 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;
}
// Alpha
@@ -11058,9 +11108,9 @@ var Phaser;
this._columnData = this.mapData[row];
for(var tile = this._startX; tile < this._startX + this._maxX; tile++) {
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._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.tileWidth, // Source Width
this.tileHeight, // Source Height
this._tx, // Destination X (where on the canvas it'll be drawn)
@@ -11121,9 +11171,11 @@ var Phaser;
Tilemap.prototype.update = function () {
};
Tilemap.prototype.render = function (camera, cameraOffsetX, cameraOffsetY) {
// Loop through the layers
for(var i = 0; i < this._layers.length; i++) {
this._layers[i].render(camera, cameraOffsetX, cameraOffsetY);
if(this.cameraBlacklist.indexOf(camera.ID) == -1) {
// Loop through the layers
for(var i = 0; i < this._layers.length; i++) {
this._layers[i].render(camera, cameraOffsetX, cameraOffsetY);
}
}
};
Tilemap.prototype.parseCSV = function (data, key, tileWidth, tileHeight) {
@@ -11806,7 +11858,7 @@ var Phaser;
};
ScrollZone.prototype.render = function (camera, cameraOffsetX, cameraOffsetY) {
// 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;
}
// Alpha
+1
View File
@@ -0,0 +1 @@
var Phaser;(function(Phaser){var Basic=(function(){function Basic(game){this.name="";this._game=game;this.ID=-1;this.exists=true;this.active=true;this.visible=true;this.alive=true;this.isGroup=false;this.ignoreDrawDebug=false}Basic.prototype.destroy=function(){};Basic.prototype.preUpdate=function(){};Basic.prototype.update=function(){};Basic.prototype.postUpdate=function(){};Basic.prototype.render=function(camera,cameraOffsetX,cameraOffsetY){};Basic.prototype.kill=function(){this.alive=false;this.exists=false};Basic.prototype.revive=function(){this.alive=true;this.exists=true};Basic.prototype.toString=function(){return""};return Basic})();Phaser.Basic=Basic})(Phaser||(Phaser={}));var Phaser;(function(Phaser){var SignalBinding=(function(){function SignalBinding(signal,listener,isOnce,listenerContext,priority){if(typeof priority==="undefined"){priority=0}this.active=true;this.params=null;this._listener=listener;this._isOnce=isOnce;this.context=listenerContext;this._signal=signal;this.priority=priority||0}SignalBinding.prototype.execute=function(paramsArr){var handlerReturn;var params;if(this.active&&!!this._listener){params=this.params?this.params.concat(paramsArr):paramsArr;handlerReturn=this._listener.apply(this.context,params);if(this._isOnce){this.detach()}}return handlerReturn};SignalBinding.prototype.detach=function(){return this.isBound()?this._signal.remove(this._listener,this.context):null};SignalBinding.prototype.isBound=function(){return(!!this._signal&&!!this._listener)};SignalBinding.prototype.isOnce=function(){return this._isOnce};SignalBinding.prototype.getListener=function(){return this._listener};SignalBinding.prototype.getSignal=function(){return this._signal};SignalBinding.prototype._destroy=function(){delete this._signal;delete this._listener;delete this.context};SignalBinding.prototype.toString=function(){return"[SignalBinding isOnce:"+this._isOnce+", isBound:"+this.isBound()+", active:"+this.active+"]"};return SignalBinding})();Phaser.SignalBinding=SignalBinding})(Phaser||(Phaser={}));var Phaser;(function(Phaser){var Signal=(function(){function Signal(){this._bindings=[];this._prevParams=null;this.memorize=false;this._shouldPropagate=true;this.active=true}Signal.VERSION="1.0.0";Signal.prototype.validateListener=function(listener,fnName){if(typeof listener!=="function"){throw new Error("listener is a required param of {fn}() and should be a Function.".replace("{fn}",fnName))}};Signal.prototype._registerListener=function(listener,isOnce,listenerContext,priority){var prevIndex=this._indexOfListener(listener,listenerContext);var binding;if(prevIndex!==-1){binding=this._bindings[prevIndex];if(binding.isOnce()!==isOnce){throw new Error("You cannot add"+(isOnce?"":"Once")+"() then add"+(!isOnce?"":"Once")+"() the same listener without removing the relationship first.")}}else{binding=new Phaser.SignalBinding(this,listener,isOnce,listenerContext,priority);this._addBinding(binding)}if(this.memorize&&this._prevParams){binding.execute(this._prevParams)}return binding};Signal.prototype._addBinding=function(binding){var n=this._bindings.length;do{--n}while(this._bindings[n]&&binding.priority<=this._bindings[n].priority);this._bindings.splice(n+1,0,binding)};Signal.prototype._indexOfListener=function(listener,context){var n=this._bindings.length;var cur;while(n--){cur=this._bindings[n];if(cur.getListener()===listener&&cur.context===context){return n}}return -1};Signal.prototype.has=function(listener,context){if(typeof context==="undefined"){context=null}return this._indexOfListener(listener,context)!==-1};Signal.prototype.add=function(listener,listenerContext,priority){if(typeof listenerContext==="undefined"){listenerContext=null}if(typeof priority==="undefined"){priority=0}this.validateListener(listener,"add");return this._registerListener(listener,false,listenerContext,priority)};Signal.prototype.addOnce=function(listener,listenerContext,priority){if(typeof listenerContext==="undefined"){listenerContext=null}if(typeof priority==="undefined"){priority=0}this.validateListener(listener,"addOnce");return this._registerListener(listener,true,listenerContext,priority)};Signal.prototype.remove=function(listener,context){if(typeof context==="undefined"){context=null}this.validateListener(listener,"remove");var i=this._indexOfListener(listener,context);if(i!==-1){this._bindings[i]._destroy();this._bindings.splice(i,1)}return listener};Signal.prototype.removeAll=function(){var n=this._bindings.length;while(n--){this._bindings[n]._destroy()}this._bindings.length=0};Signal.prototype.getNumListeners=function(){return this._bindings.length};Signal.prototype.halt=function(){this._shouldPropagate=false};Signal.prototype.dispatch=function(){var paramsArr=[];for(var _i=0;_i<(arguments.length-0);_i++){paramsArr[_i]=arguments[_i+0]}if(!this.active){return}var n=this._bindings.length;var bindings;if(this.memorize){this._prevParams=paramsArr}if(!n){return}bindings=this._bindings.slice(0);this._shouldPropagate=true;do{n--Line truncated