/
nantonenko95
/
raylib-introduction
Обзор
Документация
Войти
/
nantonenko95
/
raylib-introduction
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/sprite.cpp
42 строки
956 B
Nikita
Add collider to the player class
10 ноя 2024, 13:56
10 ноя 2024, 13:56
8c9b471
Код
Авторство
О чём код?
#include "sprite.h" void Sprite::init() { texture_ = LoadTexture(path_.c_str()); } void Sprite::draw() { Rectangle source{frameCnt_.x * frameSize_.x, frameCnt_.y * frameSize_.y, frameSize_.x, frameSize_.y}; Vec2 size = finalSize(); Rectangle dest{0, 0, size.x, size.y}; Vec2 originOffset = origin - Vec2{frameSize_.x * scale, frameSize_.y * scale} / 2; DrawTexturePro(texture_, source, dest, (-originOffset).toVector2(), rotationRad, WHITE); if (frameShowCnt + 1 < frameShowDuration) { frameShowCnt++; return; } frameShowCnt = 0; updateFrameCount(); } Vec2 Sprite::finalSize() const { return {frameSize_.x * scale, frameSize_.y * scale}; } void Sprite::updateFrameCount() { frameCnt_.x += 1; if ((size_t)frameCnt_.x == (size_t)dimens_.x) { frameCnt_.x = 0; frameCnt_.y += 1; } if ((size_t)frameCnt_.y == (size_t)dimens_.y) frameCnt_.y = 0; }