纹理加载错误(JS动画)
Textures loading error(JS Animation)
>Intruduction:我正在用JavaScript和PIXI编写一个简单的动画.js。
工作原理:我在新的地方绘制纹理,并在每一步都将其删除在旧地方。
问题:有时我会得到这些结果(某些纹理不显示并且 CPU 负载为 50%)http://itmages.ru/image/view/2649716/a5ae37b5
但是,如果我更新页面,我可以获得正常结果(并非总是如此),并且 CPU 负载为 2-3%http://itmages.ru/image/view/2649736/ca696082
法典
!函数 Animate 执行一个步骤的动画
有 3 个版本:
1)
anim();
function anim() {
setTimeout(function() {
requestAnimationFrame(anim);
animate();
}, 40);
}
2) setInterval(function() {requestAnimationFrame(animate);}, 50);
3) setInterval(animate, 50);
我使用该功能加载图片:
function presets()
{
unit_texture = new PIXI.Texture.fromImage('/assets/unit_2.png');//('/images/unit_2.png')
shell_texture = new PIXI.Texture.fromImage('/assets/shell.png'); //('/images/shell.png')
}
unit_2.png约为377字节,分辨率为(19 x 20)
shell.png约为30 KB,分辨率为(200x200)
加载后,我使用这些纹理来制作精灵(PIXI)
function Unit(id, x, y, energy, hp)
{
this.id = id;
this.x = x;
this.y = y;
this.energy = energy;
this.hp = hp;
this.sprite = new PIXI.Sprite(unit_texture);
this.sprite.width = 2 * 50;
this.sprite.height = 2 * 50;
this.sprite.anchor.x = 0.5;
this.sprite.anchor.y = 0.5;
this.sprite.position.x = x;
this.sprite.position.y = y;
stage.addChild(this.sprite);
}
在每一步中,我都会删除所有旧的 Unit 对象并创建新的 Unit 对象。
(我不能因为我的系统组织而移动它们)。
我认为这里最大的陷阱是多次制作精灵,但我还无法修复它。
PIXI。Texture.fromImage 函数是异步的。
http://www.html5gamedevs.com/topic/2620 设置纹理并不总是使用预加载图像/此问题的可能解决方案如下:
http://www.html5gamedevs.com/topic/7674-load-textures-synchronously/
- JS页面在后台加载时显示动画
- Chart.js 2.1.2条形图动画问题
- 当元素在屏幕中占60%时,WOW.js启动动画
- Famo.us Js-将实体(粒子)设置到位置的动画
- 使用JS的动画加载栏
- 设置1400个Raphael.js对象的不透明度动画会影响动画性能
- 如何在three.js中设置网格绘制的动画
- 第节上的全页JS动画
- D3.js-带有多个圆环和动画过渡的圆环图
- tween.js动画的奇怪行为
- D3.js:设置贝塞尔曲线的动画
- 来自jQuery,如何在React.js中制作DOM动画?例如设置进度条的动画
- 在动画CC中创建JS JavasScript框架脚本
- 使用wow.js显示两次动画对象
- 图表.js 2,从右到左(不是自上而下)进行动画处理
- 在拉斐尔.js中为逆时针弧线制作动画
- 如何使用citoscape制作连续动画.js
- 当 ajax 请求速度时不显示动画.js
- 动画js/jquery函数不工作
- 触发简易饼图的动画.js带有航点