Basit bir Canvas
library için bir çalışma animasyonu yöntemi yarattım Oluşturuyorum, ancak animasyon döngüsünün nasıl yapılacağını tam olarak anlayamıyorum - yöntemin kendisinden bir seçenek sunulur. Bununla demek istediğim, uygulamanın kendisinde nasıl döngü yapılacağını bildiğim, fakat sadece bir loop
parametresini geçip, benim için bunu yaparsa, değil. gerçekleştirdiği bir kez, şimdiAnimasyon döngüsü
var animate = function() {
circle.x = test.canvas.width/2;
circle.y = test.canvas.height/2;
circle.animate({
properties: {
x: test.canvas.width
},
easing: 'easeInOutExpo',
duration: 1,
callback: function() {
circle.animate({
properties: {
y: test.canvas.height
},
easing: 'easeInOutExpo',
duration: 1,
callback: animate
});
}
});
};
// 'animate` is called later on a click
ben yönteminde var kod ile:
ŞimdiCanvas.objects.Base.prototype.animate = function (options) {
options.easing = Canvas.animation.easing[options.easing] || options.easing;
options.duration = Canvas.animation.durations[options.duration] || options.duration * 1000;
var start = Date.now(),
total = start + options.duration,
old = {},
id,
self = this;
for (var i in options.properties) {
if (options.properties.hasOwnProperty(i)) {
old[i] = this[i];
}
}
(function update() {
var now = Date.now(),
progress = Math.min((options.duration - (total - now))/options.duration, 1);
for (var i in options.properties) {
if (options.properties.hasOwnProperty(i)) {
self[i] = options.easing(now - start, old[i], options.properties[i] - old[i], options.duration);
}
}
if (progress < 1) {
id = requestAnimationFrame(update);
} else {
id = cancelAnimationFrame(id);
if (options.loop) {
var animate = function() {
for (var j in options.properties) {
self[j] = old[j];
}
if (!options.callback) {
self.animate({
properties: options.properties,
easing: options.easing,
duration: options.duration,
callback: animate
});
} else {
self.animate({
properties: options.properties,
easing: options.easing,
duration: options.duration,
callback: function() {
options.callback();
animate();
}
});
}
};
options.callback = animate;
}
if (options.callback) {
options.callback();
}
}
}());
};
, burada yöntemin kendisinin dışındaki döngü çalışması yapmak zorunda code var: İşte animasyon snippet'ine İlk animasyon, animasyondan önce tüm özelliklerine geri döner, ancak sonra pencere tekrar tıklanana kadar orada oturur.
DÜZENLEME: Oh, işte code Şu an işim yok.