fixing sprites idk...
This commit is contained in:
parent
b1230534c5
commit
9f616e196c
3 changed files with 43 additions and 13 deletions
|
@ -37,7 +37,24 @@ void UpdateSpriteAnimation(SpriteAnimation self, float dt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawSpriteAnimation(SpriteAnimation spriteAnimation, Vector2 position) {
|
void DrawSpriteAnimation(SpriteAnimation spriteAnimation, Vector2 position) {
|
||||||
Vector2 drawpos = Vector2Add(position, Vector2Scale(spriteAnimation->size, 2.f));
|
#ifdef _DEBUG
|
||||||
|
DrawCircleV(position, 5, DARKGREEN);
|
||||||
|
#endif
|
||||||
|
Rectangle destination = (Rectangle){
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
spriteAnimation->size.x * spriteAnimation->scale,
|
||||||
|
spriteAnimation->size.y * spriteAnimation->scale
|
||||||
|
} ;
|
||||||
|
|
||||||
|
Vector2 origin = (Vector2){
|
||||||
|
.x = position.x + destination.width/2.f,
|
||||||
|
.y = position.y + destination.height/2.f
|
||||||
|
};
|
||||||
|
#ifdef _DEBUG
|
||||||
|
DrawCircleV(origin, 5, RED);
|
||||||
|
#endif
|
||||||
|
|
||||||
DrawTexturePro(
|
DrawTexturePro(
|
||||||
spriteAnimation->texture,
|
spriteAnimation->texture,
|
||||||
(Rectangle){
|
(Rectangle){
|
||||||
|
@ -46,16 +63,14 @@ void DrawSpriteAnimation(SpriteAnimation spriteAnimation, Vector2 position) {
|
||||||
spriteAnimation->sourceRect.width,
|
spriteAnimation->sourceRect.width,
|
||||||
spriteAnimation->sourceRect.height
|
spriteAnimation->sourceRect.height
|
||||||
},
|
},
|
||||||
(Rectangle){
|
destination,
|
||||||
position.x,
|
origin,
|
||||||
position.y,
|
|
||||||
spriteAnimation->size.x * spriteAnimation->scale,
|
|
||||||
spriteAnimation->size.y * spriteAnimation->scale
|
|
||||||
},
|
|
||||||
position,
|
|
||||||
spriteAnimation->rotation,
|
spriteAnimation->rotation,
|
||||||
WHITE
|
WHITE
|
||||||
);
|
);
|
||||||
|
#ifdef _DEBUG
|
||||||
|
DrawRectangleLinesEx(destination, 2, BLACK);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void DestroySpriteAnimation(SpriteAnimation spriteAnimation)
|
void DestroySpriteAnimation(SpriteAnimation spriteAnimation)
|
||||||
|
|
BIN
assets/karl-heinz_head.png
Normal file
BIN
assets/karl-heinz_head.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.6 KiB |
25
src/main.c
25
src/main.c
|
@ -20,24 +20,39 @@ int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
InitWindow(900, 600, "Colysis");
|
InitWindow(900, 600, "Colysis");
|
||||||
|
|
||||||
SetConfigFlags(FLAG_WINDOW_RESIZABLE | FLAG_WINDOW_UNDECORATED);
|
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
|
||||||
Texture2D gery = LoadTexture(ASSETS_PATH "/gery_hand.png");
|
Texture2D gery = LoadTexture(ASSETS_PATH "/karl-heinz_head.png");
|
||||||
|
|
||||||
SpriteAnimation geryanim = CreateSpriteAnimation(gery, (Vector2){64*5,64}, (Vector2){64,64}, 0.f, 1.f, 5, 0.2f);
|
SpriteAnimation geryanim = CreateSpriteAnimation(gery, (Vector2){64*14,64}, (Vector2){64,64}, 0.f, 4.f, 5, 0.15f);
|
||||||
|
|
||||||
|
Camera2D camera = { 0 };
|
||||||
|
camera.target = (Vector2){0,0};
|
||||||
|
camera.offset = (Vector2){GetScreenWidth()/2.f,GetScreenHeight()/2.f};
|
||||||
|
camera.rotation = 0.f;
|
||||||
|
camera.zoom = 1.f;
|
||||||
|
|
||||||
while (!WindowShouldClose()) {
|
while (!WindowShouldClose()) {
|
||||||
ClearBackground((Color){ 0x00, 0x6d, 0xfb });
|
ClearBackground((Color){ 0x00, 0x6d, 0xfb });
|
||||||
float dt = GetFrameTime();
|
float dt = GetFrameTime();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
UpdateSpriteAnimation(geryanim, dt);
|
UpdateSpriteAnimation(geryanim, dt);
|
||||||
|
|
||||||
|
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
{
|
{
|
||||||
DrawTextFull(GetFontDefault(), "Darling, I'm Home!", (Vector2){20,20}, TEXT_ORIENTATION_RIGHT, 0, 24, 5, 5, RAYWHITE);
|
BeginMode2D(camera);
|
||||||
|
{
|
||||||
|
DrawSpriteAnimation(geryanim, (Vector2){0,0});
|
||||||
|
|
||||||
DrawSpriteAnimation(geryanim, (Vector2){GetScreenWidth()/2.f, GetScreenHeight()/2.f});
|
}
|
||||||
|
EndMode2D();
|
||||||
|
|
||||||
|
{
|
||||||
|
DrawTextFull(GetFontDefault(), "Darling, I'm Home!", (Vector2){20,20}, TEXT_ORIENTATION_RIGHT, 0, 24, 5, 5, RAYWHITE);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
|
|
Loading…
Reference in a new issue