Setting Window flags right; adding animation

This commit is contained in:
n0ffie 2025-03-16 15:24:31 +01:00
parent c0e3af64d6
commit 4536c62dad
2 changed files with 30 additions and 28 deletions

View file

@ -4,6 +4,11 @@
#include "raylib.h"
#include "raymath.h"
#ifdef _DEBUG
#include <stdio.h>
#endif
SpriteAnimation CreateSpriteAnimation(Texture2D texture, Vector2 sprite_texture_dimentions, Vector2 sprite_size, float rotation, float scale, int frameCount, float speed)
{
SpriteAnimation spriteAnimation = malloc(sizeof(sprite_animation_t));
@ -37,38 +42,29 @@ void UpdateSpriteAnimation(SpriteAnimation self, float dt) {
}
void DrawSpriteAnimation(SpriteAnimation spriteAnimation, Vector2 position) {
#ifdef _DEBUG
DrawCircleV(position, 5, DARKGREEN);
#endif
Rectangle destination = (Rectangle){
0,
0,
spriteAnimation->size.x * spriteAnimation->scale,
spriteAnimation->size.y * spriteAnimation->scale
} ;
position = Vector2Scale(position, .5f);
float yscale = (spriteAnimation->size.y * spriteAnimation->scale) / 2;
float xscale = (spriteAnimation->size.x * spriteAnimation->scale) / 2;
Vector2 origin = (Vector2){
.x = position.x + destination.width/2.f,
.y = position.y + destination.height/2.f
Rectangle destination = (Rectangle) {
xscale - position.x,
yscale - position.y,
xscale + position.x,
yscale + position.y
};
#ifdef _DEBUG
DrawCircleV(origin, 5, RED);
#endif
DrawTexturePro(
spriteAnimation->texture,
(Rectangle){
spriteAnimation->sourceRect.x,
spriteAnimation->sourceRect.y,
spriteAnimation->sourceRect.width,
spriteAnimation->sourceRect.height
},
spriteAnimation->sourceRect,
destination,
origin,
(Vector2){0,0},
spriteAnimation->rotation,
WHITE
);
#ifdef _DEBUG
DrawCircleV(position, 5, DARKGREEN);
DrawRectangleLinesEx(destination, 2, BLACK);
#endif
}