Skip to content

Commit 5f9bf18

Browse files
committed
Merge branch 'feature/post-render'
2 parents 63ac686 + 4475dba commit 5f9bf18

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/DisplayListWatcher.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import WalkDisplayListObj from './WalkDisplayListObject'
66
const { POSITIVE_INFINITY } = Number
77
const TextureEvents = Phaser.Textures.Events
88
const CacheEvents = Phaser.Cache.Events
9+
const CoreEvents = Phaser.Core.Events
910
const KeyboardEvents = Phaser.Input.Keyboard.Events
1011
const SceneEvents = Phaser.Scenes.Events
1112
const { KeyCodes } = Phaser.Input.Keyboard
@@ -104,6 +105,7 @@ export class DisplayListWatcher extends Phaser.Plugins.ScenePlugin {
104105
}
105106

106107
start() {
108+
const { game } = this
107109
const { cache, events, input, make, renderer } = this.systems
108110
const fontCache = cache.bitmapFont
109111
const keyboard = input?.keyboard
@@ -119,7 +121,7 @@ export class DisplayListWatcher extends Phaser.Plugins.ScenePlugin {
119121
return
120122
}
121123

122-
events.on(SceneEvents.RENDER, this.render, this)
124+
game.events.on(CoreEvents.POST_RENDER, this.render, this)
123125

124126
this.camera = new Phaser.Cameras.Scene2D.Camera(0, 0, width, height)
125127
.setBounds(0, 0, POSITIVE_INFINITY, POSITIVE_INFINITY)
@@ -142,6 +144,7 @@ export class DisplayListWatcher extends Phaser.Plugins.ScenePlugin {
142144
}
143145

144146
stop() {
147+
const { game } = this
145148
const { cache, events, input, settings } = this.systems
146149
const keyboard = input?.keyboard
147150

@@ -150,7 +153,8 @@ export class DisplayListWatcher extends Phaser.Plugins.ScenePlugin {
150153
cache.bitmapFont.events.off(CacheEvents.ADD, this.onFontCacheAdded, this)
151154

152155
events.off(SceneEvents.UPDATE, this.update, this)
153-
events.off(SceneEvents.RENDER, this.render, this)
156+
157+
game.events.off(CoreEvents.POST_RENDER, this.render, this)
154158

155159
if (keyboard) {
156160
keyboard.off(KeyboardEvents.ANY_KEY_DOWN, this.onAnyKeyDown, this)

src/DisplayListWatcher.test.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ vi.mock('phaser', () => {
4848
ADD: 'add'
4949
}
5050
},
51+
Core: {
52+
Events: {
53+
POST_RENDER: 'postrender'
54+
}
55+
},
5156
Scenes: {
5257
Events: {
5358
BOOT: 'boot',
@@ -214,7 +219,7 @@ describe('new DisplayListWatcher(scene, pluginManager)', () => {
214219
let pluginManager
215220

216221
beforeEach(() => {
217-
game = { plugins: null }
222+
game = { events: new EventEmitter(), plugins: null }
218223
pluginManager = { game }
219224
game.plugins = pluginManager
220225
scene = {
@@ -467,13 +472,14 @@ describe('new DisplayListWatcher(scene, pluginManager)', () => {
467472
expect(updateSpy).toHaveBeenCalledTimes(1)
468473
})
469474

470-
test('after boot() and start(), scene RENDER event causes plugin render()', () => {
475+
test('after boot() and start(), game POST_RENDER event causes plugin render()', () => {
471476
const plugin = new DisplayListWatcher(scene, pluginManager)
472477
const renderSpy = vi.spyOn(plugin, 'render')
473478

474479
plugin.boot()
475480
plugin.start()
476-
plugin.systems.events.emit(Phaser.Scenes.Events.RENDER)
481+
482+
game.events.emit(Phaser.Core.Events.POST_RENDER)
477483

478484
expect(renderSpy).toHaveBeenCalledTimes(1)
479485
})
@@ -490,14 +496,15 @@ describe('new DisplayListWatcher(scene, pluginManager)', () => {
490496
expect(updateSpy).not.toHaveBeenCalled()
491497
})
492498

493-
test('after boot(), start(), stop(), scene RENDER event does not cause plugin render()', () => {
499+
test('after boot(), start(), stop(), game POST_RENDER event does not cause plugin render()', () => {
494500
const plugin = new DisplayListWatcher(scene, pluginManager)
495501
const renderSpy = vi.spyOn(plugin, 'render')
496502

497503
plugin.boot()
498504
plugin.start()
499505
plugin.stop()
500-
plugin.systems.events.emit(Phaser.Scenes.Events.RENDER)
506+
507+
game.events.emit(Phaser.Core.Events.POST_RENDER)
501508

502509
expect(renderSpy).not.toHaveBeenCalled()
503510
})

0 commit comments

Comments
 (0)