Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
С технической точки зрения "Акира" для конца 1980-х был настоящим аниме-совершенством. Это было первое аниме с частотой 24 кадра в секунду (промышленный аниме-стандарт - 12-15 кадров в секунду). this.animation = new Animation()
.addSprites(this.libcanvas.getImage('ship'), 60)
.run({
line : Array.range(0,8),
delay: 40,
loop : true
});
draw: function () {
if (this.hidden) return;
this.drawEngines();
this.libcanvas.ctx.drawImage({
image : this.animation.getSprite(),
center: this.position,
angle : this.angle + (90).degree()
});
},
var image = this.libcanvas.getImage('fire');
return new LibCanvas.Animation()
.addSprites({
small : image.sprite( 0, 0, 20, 140),
med1 : image.sprite( 20, 0, 20, 140),
med2 : image.sprite( 40, 0, 20, 140),
med3 : image.sprite( 60, 0, 20, 140),
big1 : image.sprite( 80, 0, 20, 140),
big2 : image.sprite(100, 0, 20, 140),
big3 : image.sprite(120, 0, 20, 140)
})
.add({
name : 'start',
line: ['small', 'small', 'med1', 'med2'],
delay: 40
})
.add({
name : 'moving',
loop : true, // Анимация зацикливается и меняется до ручной остановки
line : ['big1', 'big2', 'big3'],
delay : 40
})
.add({
name : 'end',
line: ['med2', 'med1', 'small', 'small'],
delay: 40
});
onMoveStart: function () {
this.fireAnimation
.stop(true)
.run('start')
.run('moving');
},
onMoveStop: function () {
this.fireAnimation
.stop(true)
.run('end');
}
this.animation = new Animation()
.addSprites(this.libcanvas.getImage('explosion'), 162)
.run({
delay: 40,
line : Array.range(0, 9)
})
.addEvent('stop', function () {
this
.stopDrawing()
.fireEvent('stop');
}.bind(this))
draw. drawImage — это тот же метод .getContext('2d').drawImage, но с возможностью задавать именованные параметры, а также вращать изображение. Минимальный код выглядит как-то так:var Explosion = atom.Class({
Extends : Drawable,
position : null,
animation: null,
initialize : function (position, image) {
this.position = position;
this.animation = new Animation()
.addSprites(image, 162)
.run({
delay: 40,
line : Array.range(0, 9)
});
},
draw : function () {
this.libcanvas.ctx.drawImage({
image : this.animation.getSprite(),
center: this.position
});
}
});
var MyObject = atom.Class({
[...],
initialize : function () {
this.animation = new Animation()
[...]
.addEvent( 'changed', this.redraw.bind(this) );
},
redraw: function () {
this.clear().draw();
},
draw : function () {
this.libcanvas.ctx.drawImage(
this.animation.getSprite(),
this.shape
);
}
});
Тоесть если твои астероиды запустились на 60FPS, а скорость движения астероида — 10 пикселей в секунду — его можно перерисовывать не каждый раз, а только 1\6 кадр( ну ладно 1\12, алиасинг ).
дин из узлов задает клип рест чтобы дети за его пределы не вылазили



Анимация и Canvas