mirror of
https://github.com/raysan5/raylib.git
synced 2025-12-06 14:23:12 +00:00
Update textures_sprite_stacking.c
This commit is contained in:
parent
646e814baf
commit
8fcd99c8dd
@ -17,7 +17,8 @@
|
|||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
#include "raymath.h"
|
|
||||||
|
#include "raymath.h" // Required for: Clamp()
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Program main entry point
|
// Program main entry point
|
||||||
@ -33,18 +34,14 @@ int main(void)
|
|||||||
|
|
||||||
Texture2D booth = LoadTexture("resources/booth.png");
|
Texture2D booth = LoadTexture("resources/booth.png");
|
||||||
|
|
||||||
// The overall scale of the stacked sprite
|
float stackScale = 3.0f; // Overall scale of the stacked sprite
|
||||||
float stackScale = 3.0f;
|
float stackSpacing = 2.0f; // Vertical spacing between each layer
|
||||||
// The vertical spacing between each layer
|
unsigned int stackCount = 122; // Number of layers, used for calculating the size of a single slice
|
||||||
float stackSpacing = 2.0f;
|
float rotationSpeed = 30.0f; // Stacked sprites rotation speed
|
||||||
// The number of layers. Used for calculating the size of a single slice
|
float rotation = 0.0f; // Current rotation of the stacked sprite
|
||||||
unsigned int stackCount = 122;
|
const float speedChange = 0.25f; // Amount speed will change by when the user presses A/D
|
||||||
// The speed to rotate the stacked sprite
|
|
||||||
float rotationSpeed = 30.0f;
|
SetTargetFPS(60);
|
||||||
// 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;
|
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
@ -57,22 +54,16 @@ int main(void)
|
|||||||
stackSpacing = Clamp(stackSpacing, 0.0f, 5.0f);
|
stackSpacing = Clamp(stackSpacing, 0.0f, 5.0f);
|
||||||
|
|
||||||
// Add a positive/negative offset to spin right/left at different speeds
|
// Add a positive/negative offset to spin right/left at different speeds
|
||||||
if (IsKeyDown(KEY_LEFT) || IsKeyDown(KEY_A))
|
if (IsKeyDown(KEY_LEFT) || IsKeyDown(KEY_A)) rotationSpeed -= speedChange;
|
||||||
{
|
if (IsKeyDown(KEY_RIGHT) || IsKeyDown(KEY_D)) rotationSpeed += speedChange;
|
||||||
rotationSpeed -= speedChange;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (IsKeyDown(KEY_RIGHT) || IsKeyDown(KEY_D))
|
rotation += rotationSpeed*GetFrameTime();
|
||||||
{
|
|
||||||
rotationSpeed += speedChange;
|
|
||||||
}
|
|
||||||
|
|
||||||
rotation += rotationSpeed * GetFrameTime();
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
// Get the size of a single slice
|
// 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
|
// 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--)
|
for (int i = stackCount - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
Rectangle source = { 0.0f, (float)i*frameHeight, frameWidth, frameHeight };
|
|
||||||
// Center vertically
|
// 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 };
|
Rectangle dest = { screenWidth/2.0f, (screenHeight/2.0f) + (i*stackSpacing) - (stackSpacing*stackCount/2.0f), scaledWidth, scaledHeight };
|
||||||
Vector2 origin = { scaledWidth/2.0f, scaledHeight/2.0f };
|
Vector2 origin = { scaledWidth/2.0f, scaledHeight/2.0f };
|
||||||
|
|
||||||
DrawTexturePro(booth, source, dest, origin, rotation, WHITE);
|
DrawTexturePro(booth, source, dest, origin, rotation, WHITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawText("a/d to spin\nmouse wheel to change separation (aka 'angle')", 10, 10, 20, DARKGRAY);
|
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(TextFormat("current spacing: %.01f", stackSpacing), 10, 50, 20, DARKGRAY);
|
||||||
DrawText(spacingText, 10, 50, 20, DARKGRAY);
|
DrawText(TextFormat("current speed: %.02f", rotationSpeed), 10, 70, 20, DARKGRAY);
|
||||||
const char *speedText = TextFormat("current speed: %.02f", rotationSpeed);
|
|
||||||
DrawText(speedText, 10, 70, 20, DARKGRAY);
|
|
||||||
DrawText("redbooth model (c) kluchek under cc 4.0", 10, 420, 20, DARKGRAY);
|
DrawText("redbooth model (c) kluchek under cc 4.0", 10, 420, 20, DARKGRAY);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user