diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ad152143..5ee33a342 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Fixed +- Fixed false positive warning when adding timers - Fixed issue where gamepad buttons wouldn't progress the default loader play button - Add defense around middling Safari fullscreen support and update documentation - Fixed issue where non-standard gamepad buttons would not be emitted by Excalibur diff --git a/src/engine/Scene.ts b/src/engine/Scene.ts index 6da71f6a7..0ce3ce2ed 100644 --- a/src/engine/Scene.ts +++ b/src/engine/Scene.ts @@ -536,14 +536,14 @@ export class Scene implements CanInitialize, CanActiv public add(screenElement: ScreenElement): void; public add(entity: any): void { this.emit('entityadded', { target: entity } as any); - this.world.add(entity); - entity.scene = this; if (entity instanceof Timer) { if (!Util.contains(this._timers, entity)) { this.addTimer(entity); } return; } + this.world.add(entity); + entity.scene = this; } /** @@ -648,8 +648,8 @@ export class Scene implements CanInitialize, CanActiv */ public remove(screenElement: ScreenElement): void; public remove(entity: any): void { + this.emit('entityremoved', { target: entity } as any); if (entity instanceof Entity) { - this.emit('entityremoved', { target: entity } as any); if (entity.isActive) { entity.kill(); } diff --git a/src/spec/TimerSpec.ts b/src/spec/TimerSpec.ts index 1ba46538b..e81d0718f 100644 --- a/src/spec/TimerSpec.ts +++ b/src/spec/TimerSpec.ts @@ -93,6 +93,19 @@ describe('A Timer', () => { expect(sut.timeElapsedTowardNextAction).toBe(0); }); + it('does not warn when added to a scene', () => { + const warnSpy = spyOn(ex.Logger.getInstance(), 'warn'); + const timerSpy = jasmine.createSpy('timer'); + const sut = new ex.Timer({ + interval: 42, + fcn: timerSpy + }); + + scene.add(sut); + + expect(warnSpy).not.toHaveBeenCalled(); + }); + it('can be stopped and started', () => { const timerSpy = jasmine.createSpy('timer'); const sut = new ex.Timer({