Ответ в теме: Анимация , класс Анимации

SFML и C++ Уроки \ Разработка игр Форумы SFML Graphics Анимация , класс Анимации Ответ в теме: Анимация , класс Анимации

#3566
Бек
Бек
Участник
Сообщений:8

Зарегистрирован:
03.04.2016

Репутация:3

решил как-то! Воовшем вот так,

в class Entity написал

float CurrentFrame = 0;//хранит текущий кадр

потом вот так

Player(Image &image, String Name, Level &lev, float X, float Y, int W, int H) :Entity(image, Name, X, Y, W, H){
playerScore = 0; state = stay; obj = lev.GetAllObjects();//инициализируем.получаем все объекты для взаимодействия персонажа с картой
if (name == “Player1″){
sprite.setTextureRect(IntRect(32, 0, 32, 32)); здесь дал координату для одного кадра

ПОтом вот

void control(){
if (Keyboard::isKeyPressed){
if (Keyboard::isKeyPressed(Keyboard::Left)) {
state = left; speed = 0.1;
CurrentFrame += 0.005 * 1, 1;
if (CurrentFrame > 3) CurrentFrame -= 3;
sprite.setTextureRect(IntRect(32 * int(CurrentFrame), 32, 32, 32));

}
if (Keyboard::isKeyPressed(Keyboard::Right)) {
state = right; speed = 0.1;
CurrentFrame += 0.005*1,1;
if (CurrentFrame > 3) CurrentFrame -= 3;
sprite.setTextureRect(IntRect(32 * int(CurrentFrame), 64, 32, 32));
}

if ((Keyboard::isKeyPressed(Keyboard::Up)) && (onGround)) {
state = jump; dy = -0.5; onGround = false ;

}

if (Keyboard::isKeyPressed(Keyboard::Down)) {
state = down;
sprite.setTextureRect(IntRect(32, 0, 32, 32));
}
}
}

Все анимация работает!