Skip to content

Commit

Permalink
[#949] Fix offscreen culling in hidpi mode (#952)
Browse files Browse the repository at this point in the history
  • Loading branch information
eonarheim authored and jedeen committed Apr 6, 2018
1 parent 920b84d commit c06518c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## Fixed

- Added missing lifecycle event handlers on Actors, Triggers, Scenes, Engine, and Camera ([#582](https://github.com/excaliburjs/Excalibur/issues/582))
- Offscreen culling in HiDPI mode ([#949](https://github.com/excaliburjs/Excalibur/issues/949))
- Correct bounds check to check drawWidth/drawHeight for HiDPI
- suppressHiDPIScaling now also suppresses pixel ratio based scaling

<!--------------------------------- DO NOT EDIT BELOW THIS LINE --------------------------------->

Expand Down
6 changes: 6 additions & 0 deletions src/engine/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,16 @@ export class Engine extends Class implements ICanInitialize, ICanUpdate, ICanDra
*/
public displayMode: DisplayMode = DisplayMode.FullScreen;


private _suppressHiDPIScaling: boolean = false;
/**
* Returns the calculated pixel ration for use in rendering
*/
public get pixelRatio(): number
{
if (this._suppressHiDPIScaling) {
return 1;
}
let devicePixelRatio = window.devicePixelRatio || 1;

let pixelRatio = devicePixelRatio;
Expand Down Expand Up @@ -965,6 +970,7 @@ O|===|* >________________>\n\

this.ctx = <CanvasRenderingContext2D>this.canvas.getContext('2d');

this._suppressHiDPIScaling = !!options.suppressHiDPIScaling;
if (!options.suppressHiDPIScaling) {
this._initializeHiDpi();
}
Expand Down
8 changes: 4 additions & 4 deletions src/engine/Traits/OffscreenCulling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export class OffscreenCulling implements IActorTrait {
if (!actor.isOffScreen) {
if ((actorScreenCoords.x + width * zoom < 0 ||
actorScreenCoords.y + height * zoom < 0 ||
actorScreenCoords.x > engine.canvasWidth ||
actorScreenCoords.y > engine.canvasHeight) &&
actorScreenCoords.x > engine.drawWidth ||
actorScreenCoords.y > engine.drawHeight) &&
isSpriteOffScreen ) {

eventDispatcher.emit('exitviewport', new ExitViewPortEvent(actor));
Expand All @@ -42,8 +42,8 @@ export class OffscreenCulling implements IActorTrait {
} else {
if ((actorScreenCoords.x + width * zoom > 0 &&
actorScreenCoords.y + height * zoom > 0 &&
actorScreenCoords.x < engine.canvasWidth &&
actorScreenCoords.y < engine.canvasHeight) ||
actorScreenCoords.x < engine.drawWidth &&
actorScreenCoords.y < engine.drawHeight) ||
!isSpriteOffScreen) {

eventDispatcher.emit('enterviewport', new EnterViewPortEvent(actor));
Expand Down
2 changes: 1 addition & 1 deletion src/spec/EngineSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ describe('The engine', () => {

engine.start().then(() => {
// Assert
expect(engine.isHiDpi).toBe(true);
expect(engine.isHiDpi).toBe(false);
expect((<any>engine)._initializeHiDpi).not.toHaveBeenCalled();
(<any>window).devicePixelRatio = 1;
done();
Expand Down

0 comments on commit c06518c

Please sign in to comment.