Skip to content

Commit

Permalink
Fixed daft issue in Camera and fully implemented tilemap collision.
Browse files Browse the repository at this point in the history
  • Loading branch information
photonstorm committed Apr 28, 2013
1 parent 4c21ac0 commit e948f1e
Show file tree
Hide file tree
Showing 15 changed files with 135 additions and 125 deletions.
Binary file added Docs/phaser logo sprite.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Docs/phaserSprite.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Docs/phaser_desert.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions Phaser/gameobjects/Emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,8 @@ module Phaser {
if (Collide > 0)
{
particle.allowCollisions = Collision.ANY;
particle.elasticity = Collide;
//particle.width *= Collide;
//particle.height *= Collide;
particle.width *= Collide;
particle.height *= Collide;
//particle.centerOffsets();
}
else
Expand Down
1 change: 1 addition & 0 deletions Phaser/gameobjects/Particle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module Phaser {

this.lifespan = 0;
this.friction = 500;

}

/**
Expand Down
3 changes: 0 additions & 3 deletions Phaser/gameobjects/Tilemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ module Phaser {

this.generateTiles(tileQuantity);

console.log('generate layer csv');

}

private parseTiledJSON(data: string, key: string) {
Expand Down Expand Up @@ -136,7 +134,6 @@ module Phaser {
layer.addColumn(row);
c = 0;
}
console.log('generate layer json');
}

layer.updateBounds();
Expand Down
8 changes: 8 additions & 0 deletions Phaser/geom/Quad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ module Phaser {
return this.y + this.height;
}

public get halfWidth(): number {
return this.width / 2;
}

public get halfHeight(): number {
return this.height / 2;
}

/**
* Determines whether the object specified intersects (overlaps) with this Quad object.
* This method checks the x, y, width, and height properties of the specified Quad object to see if it intersects with this Quad object.
Expand Down
39 changes: 23 additions & 16 deletions Phaser/system/Camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module Phaser {
private _fxShakeIntensity: number = 0;
private _fxShakeDuration: number = 0;
private _fxShakeComplete = null;
private _fxShakeOffset: Point = new Point(0, 0);
private _fxShakeOffset: MicroPoint = new MicroPoint(0, 0);
private _fxShakeDirection: number = 0;
private _fxShakePrevX: number = 0;
private _fxShakePrevY: number = 0;
Expand All @@ -77,8 +77,8 @@ module Phaser {
public ID: number;
public worldView: Rectangle;
public totalSpritesRendered: number;
public scale: Point = new Point(1, 1);
public scroll: Point = new Point(0, 0);
public scale: MicroPoint = new MicroPoint(1, 1);
public scroll: MicroPoint = new MicroPoint(0, 0);
public bounds: Rectangle = null;
public deadzone: Rectangle = null;

Expand All @@ -96,7 +96,7 @@ module Phaser {
public showShadow: bool = false;
public shadowColor: string = 'rgb(0,0,0)';
public shadowBlur: number = 10;
public shadowOffset: Point = new Point(4, 4);
public shadowOffset: MicroPoint = new MicroPoint(4, 4);

public visible: bool = true;
public alpha: number = 1;
Expand Down Expand Up @@ -230,42 +230,34 @@ module Phaser {
var w: number = this.width / 8;
var h: number = this.height / 3;
this.deadzone = new Rectangle((this.width - w) / 2, (this.height - h) / 2 - h * 0.25, w, h);
console.log('follow 1');
break;
case Camera.STYLE_TOPDOWN:
helper = Math.max(this.width, this.height) / 4;
this.deadzone = new Rectangle((this.width - helper) / 2, (this.height - helper) / 2, helper, helper);
console.log('follow 2');
break;
case Camera.STYLE_TOPDOWN_TIGHT:
helper = Math.max(this.width, this.height) / 8;
this.deadzone = new Rectangle((this.width - helper) / 2, (this.height - helper) / 2, helper, helper);
console.log('follow 3');
break;
case Camera.STYLE_LOCKON:
default:
this.deadzone = null;
console.log('follow 4');
break;
}

}

public focusOnXY(x: number, y: number) {

console.log('focusOn', x, y);

x += (x > 0) ? 0.0000001 : -0.0000001;
y += (y > 0) ? 0.0000001 : -0.0000001;

this.scroll.x = Math.round(x - this.worldView.halfWidth);
this.scroll.y = Math.round(y - this.worldView.halfHeight);

console.log('focusOn scroll',this.scroll.x, this.scroll.y);

}

public focusOn(point: Point) {
public focusOn(point) {

point.x += (point.x > 0) ? 0.0000001 : -0.0000001;
point.y += (point.y > 0) ? 0.0000001 : -0.0000001;
Expand All @@ -291,7 +283,7 @@ module Phaser {
}

this.bounds.setTo(x, y, width, height);
this.worldView.setTo(x, y, width, height);

this.scroll.setTo(0, 0);

this.update();
Expand Down Expand Up @@ -342,7 +334,7 @@ module Phaser {

}

// Make sure we didn't go outside the camera's bounds
// Make sure we didn't go outside the cameras bounds
if (this.bounds !== null)
{
if (this.scroll.x < this.bounds.left)
Expand All @@ -369,6 +361,8 @@ module Phaser {
this.worldView.x = this.scroll.x;
this.worldView.y = this.scroll.y;

//console.log(this.worldView.width, this.worldView.height);

// Input values
this.inputX = this.worldView.x + this._game.input.x;
this.inputY = this.worldView.y + this._game.input.y;
Expand Down Expand Up @@ -610,9 +604,10 @@ module Phaser {

this.worldView.width = width;
this.worldView.height = height;

this.checkClip();

//console.log('Camera setSize', width, height);

}

public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
Expand Down Expand Up @@ -652,6 +647,12 @@ module Phaser {
}

public set width(value: number) {

if (value > this._game.stage.width)
{
value = this._game.stage.width;
}

this.worldView.width = value;
this.checkClip();
}
Expand All @@ -661,6 +662,12 @@ module Phaser {
}

public set height(value: number) {

if (value > this._game.stage.height)
{
value = this._game.stage.height;
}

this.worldView.height = value;
this.checkClip();
}
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ V0.9.4
* Added Tilemap.getTile, getTileFromWorldXY, getTileFromInputXY
* Added Tilemap.setCollisionByIndex and setCollisionByRange
* Added GameObject.renderRotation boolean to control if the sprite will visually rotate or not (useful when angle needs to change but graphics don't)
* Added additional check to Camera.width/height so you cannot set them larger than the Stage size
* Added Collision.separateTile and Tilemap.collide


Requirements
Expand Down
5 changes: 4 additions & 1 deletion Tests/cameras/camera bounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
for(var i = 0; i < 100; i++) {
myGame.createSprite(Math.random() * myGame.world.width, Math.random() * myGame.world.height, 'melon');
}
myGame.onRenderCallback = render;
}
function update() {
myGame.camera.renderDebugInfo(32, 32);
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
myGame.camera.scroll.x -= 4;
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
Expand All @@ -27,4 +27,7 @@
myGame.camera.scroll.y += 4;
}
}
function render() {
myGame.camera.renderDebugInfo(32, 32);
}
})();
10 changes: 8 additions & 2 deletions Tests/cameras/camera bounds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
myGame.createSprite(Math.random() * myGame.world.width, Math.random() * myGame.world.height, 'melon');
}

myGame.onRenderCallback = render;

}

function update() {

myGame.camera.renderDebugInfo(32, 32);

if (myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
myGame.camera.scroll.x -= 4;
Expand All @@ -51,4 +51,10 @@

}

function render() {

myGame.camera.renderDebugInfo(32, 32);

}

})();
Loading

0 comments on commit e948f1e

Please sign in to comment.