2024-08-23,OffscreenCanvas 无法赋值给在屏的 ctx.drawImage
...
private _predrawFrame(frameInfo: FrameData) {
const { sx, sy, spriteIndex } = frameInfo
const { width, height } = this.onscreenCanvas
const offscreenCanvas = frameInfo.frameOffscreenCanvas
offscreenCanvas.width = width
offscreenCanvas.height = height
const { frameOffsetX, frameOffsetY, frameScaledWidth, frameScaledHeight } = this.scaleAndOffset
const { frameWidth, frameHeight } = this.spriteConfig
// 在离屏画布上绘制当前帧
const ctx = offscreenCanvas?.getContext?.('2d')!
ctx.drawImage?.(
this.spriteImageElements?.[spriteIndex],
sx,
sy,
frameWidth,
frameHeight,
frameOffsetX,
frameOffsetY,
frameScaledWidth,
frameScaledHeight,
)
}
private _drawFrame(frame: number = 0) {
const { width, height } = this.onscreenCanvas
this.onscreenCtx.clearRect(0, 0, width, height)
const frameInfo = this.frameData[frame]
const { frameOffscreenCanvas } = frameInfo
// 容器尺寸变更响应
if (frameOffscreenCanvas.width !== width || frameOffscreenCanvas.height !== height) {
this._predrawFrame(frameInfo)
}
try {
// 将离屏画布绘制到屏幕画布
this.onscreenCtx.drawImage(frameOffscreenCanvas, 0, 0)
} catch (error) {
console.log(error)
}
}
你好,麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)