Comments (6)
perhaps a helper function could be exposed to be run with in an external opt-in loop as you suggest.
Inside the requestAnimationFrame
is abstracted into an engine object. It would not be hard to make the actual content that needs to be looped into a single function and either run it in the default engine.play();
but expose it via maybe anime.update()
using getter that would automagically swap to the external loop. Only problem is that all the animations run in a single requestAnimationFrame
one would have to abstract some more to make the exposed looper function run only the desired animation otherwise it might get complicated.
This is the internal requestAnimationFrame
loop.
var engine = (function() {
var play = function() { raf = requestAnimationFrame(step); };
var step = function(t) {
if (animations.length) {
for (var i = 0; i < animations.length; i++) animations[i].tick(t);
play();
} else {
cancelAnimationFrame(raf);
raf = 0;
}
}
return play;
})();
// one could add very over simplified function to simply take over engine internally
Object.defineProperty(animation, 'update',{
get : function() {
engine.stop(); // engine.stop would have to be implemented but isn't too hard
return function(t) {
if (animations.length) for (var i = 0; i < animations.length; i++) animations[i].tick(t);
}
}
});
// then use it in your own looping system as
anime.update(yourTick);
I'm going to play around with the concept and see what is possible. I maintain a fork of anime here
from anime.
You can tell anime to not make an RAF.
Set autoplay: false
and use .tick(t)
https://github.com/ngokevin/aframe-animation-component/blob/master/index.js#L78
from anime.
Working on A-Frame, a WebVR framework. Just looking for a way to hook into the existing game loop (without introducing anime into the core library), and a way for anime to not create any requestAnimationFrame
s. Like tween's global TWEEN.tick
method.
Thanks for the library though! It exploded. If I get around to it, I can see if I can help out.
from anime.
Understand that this is closed, but this would be an excellent feature, I'm currently using anime
in my threejs
powered game engine but I am about to consolidate all raf calls into the game loop and, if I understand correctly, this is impossible with anime
. A real shame because I wouldn't like to drop anime if I didn't have to. Once I do the consolidation I'll have a look under the hood and see what I can do.
from anime.
Actually, looks like that tick()
I had was a no-op :/
from anime.
Maybe myAnimation.seek();
can do the trick?
But it's limited, and will not works with loop animations:
var myAnimation = anime({
targets: 'div',
rotate: 180,
autoplay: false
});
var raf = 0;
var speed = .5;
var loop = function() {
myAnimation.seek(raf * speed);
raf = requestAnimationFrame(loop);
}
requestAnimationFrame(loop);
An other option is to use anime
as your main RAF:
var gameLoop = anime({
update: function() {
// Do stuff
},
duration: Infinity
});
from anime.
Related Issues (20)
- JAVASCRIPT Nested OBJECT HOT 1
- Animation does not continue after pause and reversal HOT 2
- Speed up the duration during reverse playback
- Unable to use anime.js with node and express HOT 11
- Feature: ability to set innerHTML beyond numeric values HOT 1
- Spider-weeb app
- Bug report: spring-based motion not completing (Vanilla JS, HTML, CSS) HOT 4
- How to run animation on same element but with different text ? HOT 3
- can you run a for each loop in the targets? or refresh where the target is pointing to with the loopComplete callback?
- Just a question about line drawing in the docs HOT 2
- Why a cant use play/pause buttons? HOT 1
- Why cant I connect anime? HOT 1
- Does anime have a feature that can be used to implement horizontal scrolling? HOT 1
- anime.seek(0) not working HOT 3
- Anime V4 HOT 2
- Duration property problem when I use an event
- animejs morph is broken for more then 1 object HOT 1
- Refusal for Execution HOT 4
- Timeline does not draw all paths (stoke dash effect) HOT 1
- There are non-trivial differences between anime.js and anime.min.js. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from anime.