Skip to content
This repository has been archived by the owner on Nov 12, 2024. It is now read-only.

Commit

Permalink
fix resize event gets cleared on scene change
Browse files Browse the repository at this point in the history
  • Loading branch information
slmjkdbtl committed Oct 9, 2023
1 parent ef0c036 commit 02842cc
Showing 1 changed file with 37 additions and 42 deletions.
79 changes: 37 additions & 42 deletions src/kaboom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ export default (gopt: KaboomOpt = {}): KaboomCtx => {
)
}

// gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true)
gl.enable(gl.BLEND)
gl.blendFuncSeparate(
gl.SRC_ALPHA,
Expand Down Expand Up @@ -5171,7 +5172,6 @@ export default (gopt: KaboomOpt = {}): KaboomCtx => {
game.events.onOnce("frameEnd", () => {

game.events.trigger("sceneLeave", name)
// TODO: this clears the resize event
app.events.clear()
game.events.clear()
game.objEvents.clear()
Expand All @@ -5186,6 +5186,7 @@ export default (gopt: KaboomOpt = {}): KaboomCtx => {
})

game.root.clearEvents()
initEvents()

// cam
game.cam = {
Expand All @@ -5198,14 +5199,6 @@ export default (gopt: KaboomOpt = {}): KaboomCtx => {

game.scenes[name](...args)

if (gopt.debug !== false) {
enterDebugMode()
}

if (gopt.burp) {
enterBurpMode()
}

})

}
Expand Down Expand Up @@ -6521,14 +6514,6 @@ export default (gopt: KaboomOpt = {}): KaboomCtx => {

}

if (gopt.debug !== false) {
enterDebugMode()
}

if (gopt.burp) {
enterBurpMode()
}

function onLoading(action: (progress: number) => void) {
game.events.on("loading", action)
}
Expand Down Expand Up @@ -6802,37 +6787,47 @@ export default (gopt: KaboomOpt = {}): KaboomCtx => {

}

app.onHide(() => {
if (!gopt.backgroundAudio) {
audio.ctx.suspend()
}
})
function initEvents() {

app.onShow(() => {
if (!gopt.backgroundAudio) {
audio.ctx.resume()
app.onHide(() => {
if (!gopt.backgroundAudio) {
audio.ctx.suspend()
}
})

app.onShow(() => {
if (!gopt.backgroundAudio) {
audio.ctx.resume()
}
})

app.onResize(() => {
if (app.isFullscreen()) return
const fixedSize = gopt.width && gopt.height
if (fixedSize && !gopt.stretch && !gopt.letterbox) return
canvas.width = canvas.offsetWidth * pixelDensity
canvas.height = canvas.offsetHeight * pixelDensity
updateViewport()
if (!fixedSize) {
gfx.frameBuffer.free()
gfx.frameBuffer = new FrameBuffer(gl.drawingBufferWidth, gl.drawingBufferHeight)
gfx.width = gl.drawingBufferWidth / pixelDensity
gfx.height = gl.drawingBufferHeight / pixelDensity
}
})

if (gopt.debug !== false) {
enterDebugMode()
}
})

// TODO: white artifact when scrolling, but disappears when done
// TODO: if you resize to larger than the initial size it'll leave white space
// TODO: this clears on scene change
app.onResize(() => {
if (app.isFullscreen()) return
const fixedSize = gopt.width && gopt.height
if (fixedSize && !gopt.stretch && !gopt.letterbox) return
canvas.width = canvas.offsetWidth * pixelDensity
canvas.height = canvas.offsetHeight * pixelDensity
updateViewport()
if (!fixedSize) {
gfx.frameBuffer.free()
gfx.frameBuffer = new FrameBuffer(gl.drawingBufferWidth, gl.drawingBufferHeight)
gfx.width = gl.drawingBufferWidth / pixelDensity
gfx.height = gl.drawingBufferHeight / pixelDensity
if (gopt.burp) {
enterBurpMode()
}
})

}

updateViewport()
initEvents()

// the exported ctx handle
const ctx: KaboomCtx = {
Expand Down

0 comments on commit 02842cc

Please sign in to comment.