Answer the question
In order to leave comments, you need to log in
Js animation, how to organize a single interface for frames?
Good time community!
Such a situation: a 2D game, the character can walk left, right, rises up, frame animation is used.
How to use a single interface for working with frame animation?
There is a class/function:
function Sprite(){
this.size; // [30,40] - ширина и высота спрайт элемента
this.position; // [0,0] - х, у
this.frame; // [0,1,2,3,4,5,6] - кадры на спрайт-карте
}
function Elem(){
this.size = {width: 0, height: 0};
this.position = {top: 0, left: 0};
this.movement = new Sprite(); // Храним актуальный спрайт
this.sprite = {
left: new Sprite(),
right: new Sprite(),
up: new Sprite(),
}
this.status = {frame: 0, movement: 'left'};
}
Elem().movement = Elem().sprite.right
and keep working with the animation in the unified interface. Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question