javascript - 画布剪辑()没有被重置?
问题描述
我正在制作一些动画,我尝试将 3 个图像相互组合在一起,并且我在该clip()
方法上取得了部分成功。
else if(curpage==103)
{
ctx.fillStyle = "#000000";
rot = 0;
y = 1440;
a = 0.001;
}
else if(curpage==104)
{
ctx.fillStyle = "#000000";
rot = 0.6;
y = 840;
a = -0.001;
}
...
var dreamfades = function()
{
...
else if(curpage==103)
{
ctx.drawImage(img1,0,0);
ctx.save();
ctx.translate(1280,y);
ctx.rotate(rot);
ctx.rect(-1600,-465,1600,800);
ctx.clip();
ctx.rotate(-rot);
ctx.drawImage(img3,-1280,-y);
ctx.rotate(rot);
ctx.drawImage(img2,-1280,-465);
ctx.restore();
if(rot<0.3)
a+=0.0001;
else if(rot>0.6)
a=0;
else
a-=0.0001;
if(rot<0.6)
{
rot+=a;
y-=(a*1000);
}
}
else if(curpage==104)
{
ctx.fillRect(0,0,1280,720);
ctx.save();
ctx.translate(1280,y);
ctx.rotate(rot);
ctx.rect(-1600,-465,1600,800);
ctx.clip();
ctx.rotate(-rot);
ctx.drawImage(img3,-1280,-y);
ctx.rotate(rot);
ctx.drawImage(img2,-1280,-465);
ctx.restore();
if(rot>0.0)
{
a-=0.001;
rot+=a;
y-=(a*1000);
}
}
requestAnimationFrame(dreamfades)
}
img1
是背景图像。img2
是刀的图像,其中刀片是半透明的img3
是受害者的形象,将被“反映”在刀中
当用户使用curpage==103
它时,一切都按原样进行:img1
显示,然后刀在擦拭中滑动img1
,并且img3
仅显示在刀片中。但是当用户来到时curpage==104
,刀会掉下来,但img3
现在是在整个画布上而不是在画布上绘制的fillRect()
。如果用户回来curpage==103
,img3
是后台而不是img1
。如果用户转到另一个curpage
然后返回curpage==103
,img3
仍然是背景,除非刷新页面。
我有一种感觉,它clip()
以某种方式持续存在,但我不知道如何“取消剪辑()”它。我哪里错了?
解决方案
推荐阅读
- wordpress - 如果用户在没有被管理员接受的情况下无法购买商品,如何创建 woo-commerce 商店
- twitter-bootstrap - Bootstrap - 内容居中
- javascript - 排序与 if else if 在javascript中选择哪一个?
- spring - 如何通过谷歌实现授权?
- vba - 在 PowerPoint 中通过 VBA 更改链接的 Excel 文件
- node.js - 如何在 OpenCV 相机中禁用缓冲区?
- scala - 无法反序列化由 scalapb 编码的 protobuf
- sql-server - 列存储索引 - 检查已删除的行
- html - HTML CSS 居中整个站点
- android - 如何为 YouTubeView 设置访问令牌?