Html5画布,继承层次结构可能导致闪烁
Html5 canvas, inheritance hierarchy possible cause of flickering?
我正在画布中处理一个动画场景,其中我有一个基类Sprite-我的项目中除了一个对象外,其他所有对象都使用单一继承,就像从Sprite继承一样。
我有一个从精灵继承的静态动画精灵对象,这个动画精灵只是在精灵表上移动剪切区域。它按预期设置了动画,即在图纸中转换时没有闪烁。
然而,我有一个移动的动画精灵,为了节省代码空间,我从AnimatedSprite继承了这个精灵,所以这个精灵从一个从对象继承的对象继承。
这个新的精灵在每个帧转换时都会闪烁,我想知道双重继承是否会导致这个问题?就像搜索所有三个对象的原型以查找函数调用一样?
很抱歉,在不尝试的情况下询问有点懒惰,代码库相当大,今晚我没有时间使用单一继承模型重写对象。
因此,如有任何评论,我们将不胜感激!
记录在案,我是双重缓冲。
继承函数:
function __extends(child,parent){ //Global function for inheriting from objects
function Temp(){this.constructor = child;} //Create a temporary ctor
Temp.prototype = parent.prototype;
child.prototype = new Temp(); //Set the child to an object with the child's ctor with the parents prototype
}
交换帧:
SantaSprite.prototype.loopImages = function(){
if(this.getDirection()){ //If going right set the y frame to the bottom of the sheet
this.setCurrentFrame(this.getCurrentFrame().getX(),this.getFrameHeight());
}
else{ //Else set y to the top of the sheet
this.setCurrentFrame(this.getCurrentFrame().getX(),0);
}
this.setSwitchTime(this.getSwitchTime()+this.getIncrement()); //Increment the timer
if(this.getSwitchTime() >= this.getSwitchFrame()){ //If the counter has reached the limit
this.setSwitchTime(0); //Reset the counter
//Move the frame along one tile in the x axis
this.setCurrentFrame(this.getCurrentFrame().getX() + this.getFrameWidth());
//If at the end of x axis, reset back to 0 (left)
if(this.getCurrentFrame().getX() + this.getFrameWidth() > this.getImage().width){
this.setCurrentFrame(0,this.getCurrentFrame().getY());
}
}
};
干杯
这里的错误在这一行:
//Move the frame along one tile in the x axis
this.setCurrentFrame(this.getCurrentFrame().getX() + this.getFrameWidth()); //No Y value set.
修复:
//Move the frame along one tile in the x axis
this.setCurrentFrame(this.getCurrentFrame().getX() + this.getFrameWidth(),
this.getCurrentFrame().getY());
相关文章:
- 从json对象聚集数据并创建层次结构
- Html5-使用SVG路径绘制的组织层次结构在左手边被剪裁
- 使用jquery为移动布局更改html层次结构
- 如何在javascript中使用2个一维数组创建层次结构树
- 从d3.js中的csv创建树层次结构
- D3:使用 nest 函数将带有父键的平面数据转换为层次结构
- JSON 层次结构,如何获取元素
- 展平多个嵌套层次结构数组-d3.js
- Kendo UI层次结构DataSource架构不工作
- 用于构建树节点层次结构的javascript库
- 如何在JavaScript中显示注释线程层次结构
- js初学者-如何获得网页中所选内容的html以及整个节点层次结构
- Jquery选择层次结构
- 无法通过jQuery查找来定位层次结构中的对象
- Html5画布,继承层次结构可能导致闪烁
- d3.js-通过csv显示饼图中的层次结构
- 如果其他语句层次结构 JS
- 跨度外部背景控制的层次结构
- 简单的层次结构与jQuery移动嵌套列表+挖空.js
- 如何在node.js应用程序中的mongodb中按层次结构顺序插入数据