小游戏的裁剪(比如 滚动区间)怎么做
发布于 4 年前 作者 jkong 11783 次浏览 来自 问答

requestAnimationFrame 和 canvas 的 clip 一起时,会非常卡顿,

那如果想在小游戏中实现类似 scroll-view 这样的对象,只显示部分内容的裁剪效果,该怎么做呢

1 回复

解决方案如下:

ctx.fillRect(x, y, width, height);  // 遮罩层尺寸

ctx.globalCompositeOperation = “source-atop”;

// 中间加显示内容

ctx.globalCompositeOperation = “source-over”;

回到顶部