A single C++ header file library for sprite-sheet animations in Raylib.
Here is what you need to have set up to get started using AnimatorForRaylib.
- Raylib source and library files
- Visual Studio project that can run a Raylib application
- Download the latest release from the 'Releases' tab.
- Extract the zip file and place the extracted folder in your Visual Studio Solution directory.
- Open your VS Solution.
- Right click on your project, go to Properties.
- Go to C/C++ > General, add
$(SolutionDir)AnimatorForRaylib\Include;
in 'Additional Include Directories'. - Go to Linker > General, add
$(SolutionDir)AnimatorForRaylib\Library\$(PlatformTarget)\$(Configuration)\;
in 'Additional Library Directories'. - Go to Linker > Input, add
AnimatorForRaylib.lib;
in 'Additional Dependencies'. - Click 'Apply' and click 'Ok'.
#include <raylib.h>
#include "Animator.h"
Animator SpriteAnimator{"GiveItAName", Columns:5, Rows:5, Speed:10};
Texture2D Sprite;
Vector2 Location;
int main()
{
const int ScreenWidth = 800;
const int ScreenHeight = 450;
InitWindow(ScreenWidth, ScreenHeight, "raylib [core] C++ example - basic window");
SetTargetFPS(120);
Sprite = LoadTexture("PathToSpritesheet/SpriteName.png");
Location = {300.0f, 200.0f};
SpriteAnimator.AssignSprite(Sprite);
while (!WindowShouldClose())
{
// Update
SpriteAnimator.Play();
// Draw
BeginDrawing();
ClearBackground(RAYWHITE);
DrawTextureRec(SpriteAnimator.GetSprite(), SpriteAnimator.GetFrameRec(), Location, WHITE);
EndDrawing();
}
UnloadTexture(Sprite);
CloseWindow();
return 0;
}
Build and run the application.