Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JS tween how to improve?

Im trying to make a simple expo tween, it works, but its a bit jittery and FF seems to hang a bit. What can I do to improve it?

var distance = (target - x) * dir;

x += (distance / 5) * dir;

if (dir == 1 && x >= target-1) {
    return;
    }

if (dir == -1 && x <= target+1) {
     return;
    }
like image 263
davivid Avatar asked Sep 29 '10 21:09

davivid


People also ask

How do I use tween with 3JS?

Tutorial using tween.js with three.js You need to install npm first–this comes with node.js, so install that one first. Then, cd to tween.js ’s directory and run:

How to tell tween to run when it updates?

Check 04-simplest for a working example. Tween.js doesn’t run by itself. You need to tell it when to run, by explicitly calling the update method. The recommended method is to do this inside your main animation loop, which should be called with requestAnimationFrame for getting the best graphics performance:

How do I add tween to node?

You need to install npm first–this comes with node.js, so install that one first. Then, cd to tween.js ’s directory and run: If you want to add any feature or change existing features, you must run the tests to make sure you didn’t break anything else.

How can I avoid slowing down my projects when using tween?

Here are some of the ways you can avoid slowing down your projects when using Tween.js (or when animating in the web, in general). When you try to animate the position of an element in the page, the easiest solution is to animate the top and left style properties, like this:


1 Answers

You'll probably find your answer and more looking at the source of tween.js

All tween curves visualized: http://sole.github.com/tween.js/examples/03_graphs.html

like image 100
antonj Avatar answered Sep 22 '22 23:09

antonj