Skip to content

Commit

Permalink
Merge 12cdba7 into 0c2f7ed
Browse files Browse the repository at this point in the history
  • Loading branch information
eonarheim committed Oct 12, 2018
2 parents 0c2f7ed + 12cdba7 commit 1f12f9a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -18,6 +18,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### Fixed


- Fixed issue where pointer events do not work in mobile ([#1044](https://github.com/excaliburjs/Excalibur/issues/1044))
- Fixed issue where iOS was not loading by including the right polyfills ([#1043](https://github.com/excaliburjs/Excalibur/issues/1043))
- Fixed issue where sprites do not work in Firefox ([#980](https://github.com/excaliburjs/Excalibur/issues/978))
- Fixed issue where collision pairs could sometimes be incorrect ([#975](https://github.com/excaliburjs/Excalibur/issues/975))
Expand Down
10 changes: 8 additions & 2 deletions src/engine/Input/Pointer.ts
Expand Up @@ -837,7 +837,10 @@ export class Pointer extends Class {
* @param actor An Actor for check;
*/
public isActorUnderPointer(actor: Actor): boolean {
return actor.contains(this.lastWorldPos.x, this.lastWorldPos.y, !Actors.isUIActor(actor));
if (this.lastWorldPos) {
return actor.contains(this.lastWorldPos.x, this.lastWorldPos.y, !Actors.isUIActor(actor));
}
return false;
}

/**
Expand All @@ -854,7 +857,10 @@ export class Pointer extends Class {
this.lastWorldPos = new Vector(ev.worldPos.x, ev.worldPos.y);
}

private _onPointerDown(): void {
private _onPointerDown(ev: PointerEvent): void {
this.lastPagePos = new Vector(ev.pagePos.x, ev.pagePos.y);
this.lastScreenPos = new Vector(ev.screenPos.x, ev.screenPos.y);
this.lastWorldPos = new Vector(ev.worldPos.x, ev.worldPos.y);
this._isDown = true;
}

Expand Down
19 changes: 18 additions & 1 deletion src/spec/PointerInputSpec.ts
Expand Up @@ -98,7 +98,11 @@ describe('A pointer', () => {
expect(eventMoveFired).toBeTruthy();
});

it('should update last position', () => {
it('should update last position on down and move', () => {
executeMouseEvent('pointerdown', <any>document, null, 10, 800);
expect(engine.input.pointers.primary.lastPagePos.x).toBe(10);
expect(engine.input.pointers.primary.lastPagePos.y).toBe(800);

executeMouseEvent('pointermove', <any>document, null, 100, 200);

expect(engine.input.pointers.primary.lastPagePos.x).toBe(100);
Expand All @@ -109,4 +113,17 @@ describe('A pointer', () => {
expect(engine.input.pointers.primary.lastPagePos.x).toBe(300);
expect(engine.input.pointers.primary.lastPagePos.y).toBe(400);
});

it('should not throw when checking if actors are under pointer if no pointer events have happened yet', () => {
let actor = new ex.Actor({ x: 50, y: 50, width: 100, height: 100 });
expect(() => engine.input.pointers.primary.isActorUnderPointer(actor)).not.toThrowError();
expect(engine.input.pointers.primary.isActorUnderPointer(actor)).toBe(false);
});

it('should return true when an actor is under the pointer', () => {
let actor = new ex.Actor({ x: 50, y: 50, width: 100, height: 100 });
executeMouseEvent('pointerdown', <any>document, null, 50, 50);

expect(engine.input.pointers.primary.isActorUnderPointer(actor)).toBe(true);
});
});

0 comments on commit 1f12f9a

Please sign in to comment.