From 8fcd99c8ddbaa3e4a130bbff82e7c36c82758cc6 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 19 Nov 2025 19:41:39 +0100 Subject: [PATCH] Update textures_sprite_stacking.c --- examples/textures/textures_sprite_stacking.c | 50 ++++++++------------ 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/examples/textures/textures_sprite_stacking.c b/examples/textures/textures_sprite_stacking.c index a2cb04d2f..5edc1af6b 100644 --- a/examples/textures/textures_sprite_stacking.c +++ b/examples/textures/textures_sprite_stacking.c @@ -17,7 +17,8 @@ ********************************************************************************************/ #include "raylib.h" -#include "raymath.h" + +#include "raymath.h" // Required for: Clamp() //------------------------------------------------------------------------------------ // Program main entry point @@ -33,18 +34,14 @@ int main(void) Texture2D booth = LoadTexture("resources/booth.png"); - // The overall scale of the stacked sprite - float stackScale = 3.0f; - // The vertical spacing between each layer - float stackSpacing = 2.0f; - // The number of layers. Used for calculating the size of a single slice - unsigned int stackCount = 122; - // The speed to rotate the stacked sprite - float rotationSpeed = 30.0f; - // The current rotation of the stacked sprite - float rotation = 0.0f; - // The amount that speed will change by when the user presses A/D - const float speedChange = 0.25f; + float stackScale = 3.0f; // Overall scale of the stacked sprite + float stackSpacing = 2.0f; // Vertical spacing between each layer + unsigned int stackCount = 122; // Number of layers, used for calculating the size of a single slice + float rotationSpeed = 30.0f; // Stacked sprites rotation speed + float rotation = 0.0f; // Current rotation of the stacked sprite + const float speedChange = 0.25f; // Amount speed will change by when the user presses A/D + + SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop @@ -57,22 +54,16 @@ int main(void) stackSpacing = Clamp(stackSpacing, 0.0f, 5.0f); // Add a positive/negative offset to spin right/left at different speeds - if (IsKeyDown(KEY_LEFT) || IsKeyDown(KEY_A)) - { - rotationSpeed -= speedChange; - } - - if (IsKeyDown(KEY_RIGHT) || IsKeyDown(KEY_D)) - { - rotationSpeed += speedChange; - } - - rotation += rotationSpeed * GetFrameTime(); + if (IsKeyDown(KEY_LEFT) || IsKeyDown(KEY_A)) rotationSpeed -= speedChange; + if (IsKeyDown(KEY_RIGHT) || IsKeyDown(KEY_D)) rotationSpeed += speedChange; + + rotation += rotationSpeed*GetFrameTime(); //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); + ClearBackground(RAYWHITE); // Get the size of a single slice @@ -86,20 +77,19 @@ int main(void) // Draw the stacked sprite, rotated to the correct angle, with an vertical offset applied based on its y location for (int i = stackCount - 1; i >= 0; i--) { - Rectangle source = { 0.0f, (float)i*frameHeight, frameWidth, frameHeight }; // Center vertically + Rectangle source = { 0.0f, (float)i*frameHeight, frameWidth, frameHeight }; Rectangle dest = { screenWidth/2.0f, (screenHeight/2.0f) + (i*stackSpacing) - (stackSpacing*stackCount/2.0f), scaledWidth, scaledHeight }; Vector2 origin = { scaledWidth/2.0f, scaledHeight/2.0f }; DrawTexturePro(booth, source, dest, origin, rotation, WHITE); } - DrawText("a/d to spin\nmouse wheel to change separation (aka 'angle')", 10, 10, 20, DARKGRAY); - const char *spacingText = TextFormat("current spacing: %.01f", stackSpacing); - DrawText(spacingText, 10, 50, 20, DARKGRAY); - const char *speedText = TextFormat("current speed: %.02f", rotationSpeed); - DrawText(speedText, 10, 70, 20, DARKGRAY); + DrawText("A/D to spin\nmouse wheel to change separation (aka 'angle')", 10, 10, 20, DARKGRAY); + DrawText(TextFormat("current spacing: %.01f", stackSpacing), 10, 50, 20, DARKGRAY); + DrawText(TextFormat("current speed: %.02f", rotationSpeed), 10, 70, 20, DARKGRAY); DrawText("redbooth model (c) kluchek under cc 4.0", 10, 420, 20, DARKGRAY); + EndDrawing(); //---------------------------------------------------------------------------------- }