小游戏的裁剪(比如 滚动区间)怎么做

发布于 6 年前作者 jkong12043 次浏览最后编辑 6 年前来自 ask

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

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

1 回复
iyi
iyi1 楼4 年前

解决方案如下:

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

ctx.globalCompositeOperation = “source-atop”;

// 中间加显示内容

ctx.globalCompositeOperation = “source-over”;