Skip to content

Commit 2de70d0

Browse files
committed
Fixed issue in Camera.inCamera check where it wouldn't take into consideration the Sprites scrollFactor.
1 parent b951b02 commit 2de70d0

22 files changed

Lines changed: 2254 additions & 121 deletions

Phaser/Game.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,9 @@ module Phaser {
302302
this.framerate = 60;
303303
this.isBooted = true;
304304

305+
// Set-up some static helper references
306+
ColorUtils.game = this;
307+
305308
// Display the default game screen?
306309
if (this.onInitCallback == null && this.onCreateCallback == null && this.onUpdateCallback == null && this.onRenderCallback == null && this._pendingState == null)
307310
{

Phaser/Phaser.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,14 @@
173173
<Content Include="utils\CircleUtils.js">
174174
<DependentUpon>CircleUtils.ts</DependentUpon>
175175
</Content>
176+
<TypeScriptCompile Include="utils\PixelUtils.ts" />
177+
<TypeScriptCompile Include="utils\ColorUtils.ts" />
178+
<Content Include="utils\ColorUtils.js">
179+
<DependentUpon>ColorUtils.ts</DependentUpon>
180+
</Content>
181+
<Content Include="utils\PixelUtils.js">
182+
<DependentUpon>PixelUtils.ts</DependentUpon>
183+
</Content>
176184
<Content Include="utils\PointUtils.js">
177185
<DependentUpon>PointUtils.ts</DependentUpon>
178186
</Content>

Phaser/cameras/Camera.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,11 @@ module Phaser {
474474
this._game.stage.context.globalAlpha = 1;
475475
}
476476

477+
// Debug test
478+
this._game.stage.context.fillStyle = 'rgba(255,0,0,0.3)';
479+
//this._game.stage.context.fillRect(this.scaledX, this.scaledY, this.worldView.width, this.worldView.height);
480+
this._game.stage.context.fillRect(this.worldView.x, this.worldView.y, this.worldView.width, this.worldView.height);
481+
477482
}
478483

479484
/**

Phaser/gameobjects/DynamicTexture.ts

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// <reference path="../Game.ts" />
22
/// <reference path="../utils/RectangleUtils.ts" />
3+
/// <reference path="../utils/ColorUtils.ts" />
34
/// <reference path="IGameObject.ts" />
45

56
/**
@@ -90,7 +91,7 @@ module Phaser {
9091
//a = imageData.data[3];
9192
var imageData = this.context.getImageData(x, y, 1, 1);
9293

93-
return this.getColor(imageData.data[0], imageData.data[1], imageData.data[2]);
94+
return ColorUtils.getColor(imageData.data[0], imageData.data[1], imageData.data[2]);
9495

9596
}
9697

@@ -104,7 +105,7 @@ module Phaser {
104105

105106
var imageData = this.context.getImageData(x, y, 1, 1);
106107

107-
return this.getColor32(imageData.data[3], imageData.data[0], imageData.data[1], imageData.data[2]);
108+
return ColorUtils.getColor32(imageData.data[3], imageData.data[0], imageData.data[1], imageData.data[2]);
108109

109110
}
110111

@@ -288,37 +289,6 @@ module Phaser {
288289
return this.bounds.height;
289290
}
290291

291-
/**
292-
* Given an alpha and 3 color values this will return an integer representation of it
293-
*
294-
* @param alpha {number} The Alpha value (between 0 and 255)
295-
* @param red {number} The Red channel value (between 0 and 255)
296-
* @param green {number} The Green channel value (between 0 and 255)
297-
* @param blue {number} The Blue channel value (between 0 and 255)
298-
*
299-
* @return A native color value integer (format: 0xAARRGGBB)
300-
*/
301-
private getColor32(alpha: number, red: number, green: number, blue: number): number {
302-
303-
return alpha << 24 | red << 16 | green << 8 | blue;
304-
305-
}
306-
307-
/**
308-
* Given 3 color values this will return an integer representation of it
309-
*
310-
* @param red {number} The Red channel value (between 0 and 255)
311-
* @param green {number} The Green channel value (between 0 and 255)
312-
* @param blue {number} The Blue channel value (between 0 and 255)
313-
*
314-
* @return A native color value integer (format: 0xRRGGBB)
315-
*/
316-
private getColor(red: number, green: number, blue: number): number {
317-
318-
return red << 16 | green << 8 | blue;
319-
320-
}
321-
322292
}
323293

324294
}

Phaser/input/Pointer.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,6 @@ module Phaser {
374374
}
375375
}
376376

377-
//console.log('highest priority was', _highestPriority);
378-
379377
if (this.isDown)
380378
{
381379
// Now update all objects with the highest priority ID (can be more than 1)

Phaser/renderers/CanvasRenderer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ module Phaser {
9090
return true;
9191
}
9292

93-
this._dx = sprite.frameBounds.x - camera.worldView.x;
94-
this._dy = sprite.frameBounds.y - camera.worldView.y;
93+
this._dx = sprite.frameBounds.x - (camera.worldView.x * sprite.scrollFactor.x);
94+
this._dy = sprite.frameBounds.y - (camera.worldView.y * sprite.scrollFactor.y);
9595
this._dw = sprite.frameBounds.width * sprite.scale.x;
9696
this._dh = sprite.frameBounds.height * sprite.scale.y;
9797

98-
return (camera.worldView.right > this._dx) && (camera.worldView.x < this._dx + this._dw) && (camera.worldView.bottom > this._dy) && (camera.worldView.y < this._dy + this._dh);
98+
return (camera.scaledX + camera.worldView.width > this._dx) && (camera.scaledX < this._dx + this._dw) && (camera.scaledY + camera.worldView.height > this._dy) && (camera.scaledY < this._dy + this._dh);
9999

100100
}
101101

0 commit comments

Comments
 (0)