Skip to content

Commit e948f1e

Browse files
committed
Fixed daft issue in Camera and fully implemented tilemap collision.
1 parent 4c21ac0 commit e948f1e

15 files changed

Lines changed: 135 additions & 125 deletions

File tree

Docs/phaser logo sprite.gif

3.57 KB
Loading

Docs/phaserSprite.gif

531 Bytes
Loading

Docs/phaser_desert.png

106 KB
Loading

Phaser/gameobjects/Emitter.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,8 @@ module Phaser {
237237
if (Collide > 0)
238238
{
239239
particle.allowCollisions = Collision.ANY;
240-
particle.elasticity = Collide;
241-
//particle.width *= Collide;
242-
//particle.height *= Collide;
240+
particle.width *= Collide;
241+
particle.height *= Collide;
243242
//particle.centerOffsets();
244243
}
245244
else

Phaser/gameobjects/Particle.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module Phaser {
2222

2323
this.lifespan = 0;
2424
this.friction = 500;
25+
2526
}
2627

2728
/**

Phaser/gameobjects/Tilemap.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ module Phaser {
9797

9898
this.generateTiles(tileQuantity);
9999

100-
console.log('generate layer csv');
101-
102100
}
103101

104102
private parseTiledJSON(data: string, key: string) {
@@ -136,7 +134,6 @@ module Phaser {
136134
layer.addColumn(row);
137135
c = 0;
138136
}
139-
console.log('generate layer json');
140137
}
141138

142139
layer.updateBounds();

Phaser/geom/Quad.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ module Phaser {
6868
return this.y + this.height;
6969
}
7070

71+
public get halfWidth(): number {
72+
return this.width / 2;
73+
}
74+
75+
public get halfHeight(): number {
76+
return this.height / 2;
77+
}
78+
7179
/**
7280
* Determines whether the object specified intersects (overlaps) with this Quad object.
7381
* This method checks the x, y, width, and height properties of the specified Quad object to see if it intersects with this Quad object.

Phaser/system/Camera.ts

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ module Phaser {
6060
private _fxShakeIntensity: number = 0;
6161
private _fxShakeDuration: number = 0;
6262
private _fxShakeComplete = null;
63-
private _fxShakeOffset: Point = new Point(0, 0);
63+
private _fxShakeOffset: MicroPoint = new MicroPoint(0, 0);
6464
private _fxShakeDirection: number = 0;
6565
private _fxShakePrevX: number = 0;
6666
private _fxShakePrevY: number = 0;
@@ -77,8 +77,8 @@ module Phaser {
7777
public ID: number;
7878
public worldView: Rectangle;
7979
public totalSpritesRendered: number;
80-
public scale: Point = new Point(1, 1);
81-
public scroll: Point = new Point(0, 0);
80+
public scale: MicroPoint = new MicroPoint(1, 1);
81+
public scroll: MicroPoint = new MicroPoint(0, 0);
8282
public bounds: Rectangle = null;
8383
public deadzone: Rectangle = null;
8484

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

101101
public visible: bool = true;
102102
public alpha: number = 1;
@@ -230,42 +230,34 @@ module Phaser {
230230
var w: number = this.width / 8;
231231
var h: number = this.height / 3;
232232
this.deadzone = new Rectangle((this.width - w) / 2, (this.height - h) / 2 - h * 0.25, w, h);
233-
console.log('follow 1');
234233
break;
235234
case Camera.STYLE_TOPDOWN:
236235
helper = Math.max(this.width, this.height) / 4;
237236
this.deadzone = new Rectangle((this.width - helper) / 2, (this.height - helper) / 2, helper, helper);
238-
console.log('follow 2');
239237
break;
240238
case Camera.STYLE_TOPDOWN_TIGHT:
241239
helper = Math.max(this.width, this.height) / 8;
242240
this.deadzone = new Rectangle((this.width - helper) / 2, (this.height - helper) / 2, helper, helper);
243-
console.log('follow 3');
244241
break;
245242
case Camera.STYLE_LOCKON:
246243
default:
247244
this.deadzone = null;
248-
console.log('follow 4');
249245
break;
250246
}
251247

252248
}
253249

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

256-
console.log('focusOn', x, y);
257-
258252
x += (x > 0) ? 0.0000001 : -0.0000001;
259253
y += (y > 0) ? 0.0000001 : -0.0000001;
260254

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

264-
console.log('focusOn scroll',this.scroll.x, this.scroll.y);
265-
266258
}
267259

268-
public focusOn(point: Point) {
260+
public focusOn(point) {
269261

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

293285
this.bounds.setTo(x, y, width, height);
294-
this.worldView.setTo(x, y, width, height);
286+
295287
this.scroll.setTo(0, 0);
296288

297289
this.update();
@@ -342,7 +334,7 @@ module Phaser {
342334

343335
}
344336

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

364+
//console.log(this.worldView.width, this.worldView.height);
365+
372366
// Input values
373367
this.inputX = this.worldView.x + this._game.input.x;
374368
this.inputY = this.worldView.y + this._game.input.y;
@@ -610,9 +604,10 @@ module Phaser {
610604

611605
this.worldView.width = width;
612606
this.worldView.height = height;
613-
614607
this.checkClip();
615608

609+
//console.log('Camera setSize', width, height);
610+
616611
}
617612

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

654649
public set width(value: number) {
650+
651+
if (value > this._game.stage.width)
652+
{
653+
value = this._game.stage.width;
654+
}
655+
655656
this.worldView.width = value;
656657
this.checkClip();
657658
}
@@ -661,6 +662,12 @@ module Phaser {
661662
}
662663

663664
public set height(value: number) {
665+
666+
if (value > this._game.stage.height)
667+
{
668+
value = this._game.stage.height;
669+
}
670+
664671
this.worldView.height = value;
665672
this.checkClip();
666673
}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ V0.9.4
2424
* Added Tilemap.getTile, getTileFromWorldXY, getTileFromInputXY
2525
* Added Tilemap.setCollisionByIndex and setCollisionByRange
2626
* Added GameObject.renderRotation boolean to control if the sprite will visually rotate or not (useful when angle needs to change but graphics don't)
27+
* Added additional check to Camera.width/height so you cannot set them larger than the Stage size
28+
* Added Collision.separateTile and Tilemap.collide
2729

2830

2931
Requirements

Tests/cameras/camera bounds.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
for(var i = 0; i < 100; i++) {
1414
myGame.createSprite(Math.random() * myGame.world.width, Math.random() * myGame.world.height, 'melon');
1515
}
16+
myGame.onRenderCallback = render;
1617
}
1718
function update() {
18-
myGame.camera.renderDebugInfo(32, 32);
1919
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
2020
myGame.camera.scroll.x -= 4;
2121
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
@@ -27,4 +27,7 @@
2727
myGame.camera.scroll.y += 4;
2828
}
2929
}
30+
function render() {
31+
myGame.camera.renderDebugInfo(32, 32);
32+
}
3033
})();

0 commit comments

Comments
 (0)