mirror of
https://github.com/wassname/phaser.git
synced 2026-07-08 00:10:32 +08:00
New v0.9.3 release - see the changelog in the README for full details.
This commit is contained in:
+16
-13
@@ -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
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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() {
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
})();
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
@@ -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
|
||||
Vendored
+1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user