I’m working on a 2D animation system. You can find an example of it in action over at http://artisanimation.com/UnimHTML/TapTitans2Web.html
Every frame there is UV manipulation and vertex matrix manipulation. I’m not sure why, but this example may crash or slow down devices.
I’m new to javascript so any help deciphering the issue would be much appriciated!!!
At first sight, i see at least two things you can improve:
Your animation loop is not correct. There is no need to use setTimeout(). This should be sufficient:
function animate() {
requestAnimationFrame( animate );
updateAnim( swordMasterAnim );
updateAnim( monsterAnim );
renderer.render( scene, camera );
}
Besides, you allocate way to many objects in each update step. Try to reuse objects and avoid instantiation via the new operator or object literals. If you use Chrome, you can easily monitor the resource consumption of your app with the built-in task manager.
Thanks for the reply, much appreciated!! I thought I was reusing objects? Are you saying I need to use fewer objects just in general? also how do i specify the frame rate with your solution?
Try to avoid this. Instead, reuse the arrays and just change their content. Your app will allocate less memory and the garbage collection has less work to do.
As i mentioned before, your animation loop is still not correct. Can you please fix this in order to ensure that it is not the source of your problem? It should be:
function animate() {
requestAnimationFrame( animate );
updateAnim( swordMasterAnim );
updateAnim( monsterAnim );
renderer.render( scene, camera );
}
I made it reference three.js as apposed to min.js. I’ll look into removing the {}. thanks for letting me know I didn’t know that new object gets created. Every single time . that may be a huge issue
It’s important to know that objects of type Geometry are internally converted to BufferGeometry. The mentioned line of code will trigger a conversion each frame which is of course unfavorable. If you only update uv coordinates, you can remove this line. uvsNeedUpdate should be sufficient.
Also consider to develop directly with BufferGeometry to avoid any conversion overhead.