#include "coin.h" #define SPRITE_NUMBERS 31 void Coin::Init() { pos = {800, 400}; CoinSprite = LoadTexture("Assets/coinspritesheets.png"); // Texture loading frameRec = { 0.0f, 0.0f, (float)CoinSprite.width/SPRITE_NUMBERS, (float)CoinSprite.height }; currentFrame = 0; framesCounter = 0; framesSpeed = 16; // Number of spritesheet frames shown by second } void Coin::Update() { framesCounter++; if (framesCounter >= (60/framesSpeed)) // FPS를 60으로 설정했으므로 60을 프레임스피드로 나눈다. 그러면 1초당 몇번 돌릴지 결과 값이 나온다. { framesCounter = 0; currentFrame++; if (currentFrame > SPRITE_NUMBERS) currentFrame = 0; frameRec.x = (float)currentFrame*(float)CoinSprite.width/SPRITE_NUMBERS; } } void Coin::Draw() { DrawTextureRec(CoinSprite, frameRec, pos, WHITE); // Draw part of the texture } Coin::~Coin() { UnloadTexture(CoinSprite); // Texture unloading }