From e121058eb625c3d54ec8ec3eab0289c9a99fd086 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 7 Jul 2022 12:09:30 +0200 Subject: RENAMED: example: textures_rectangle -> textures_sprite_anim --- examples/Makefile | 5 +- examples/Makefile.Web | 4 +- examples/README.md | 4 +- examples/textures/textures_rectangle.c | 102 ---------------------------- examples/textures/textures_rectangle.png | Bin 39809 -> 0 bytes examples/textures/textures_sprite_anim.c | 103 +++++++++++++++++++++++++++++ examples/textures/textures_sprite_anim.png | Bin 0 -> 39809 bytes 7 files changed, 111 insertions(+), 107 deletions(-) delete mode 100644 examples/textures/textures_rectangle.c delete mode 100644 examples/textures/textures_rectangle.png create mode 100644 examples/textures/textures_sprite_anim.c create mode 100644 examples/textures/textures_sprite_anim.png (limited to 'examples') diff --git a/examples/Makefile b/examples/Makefile index 636f5ec6..8517a91c 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -413,7 +413,6 @@ SHAPES = \ TEXTURES = \ textures/textures_logo_raylib \ textures/textures_mouse_painting \ - textures/textures_rectangle \ textures/textures_srcrec_dstrec \ textures/textures_image_drawing \ textures/textures_image_generation \ @@ -425,12 +424,14 @@ TEXTURES = \ textures/textures_particles_blending \ textures/textures_npatch_drawing \ textures/textures_background_scrolling \ + textures/textures_sprite_anim \ textures/textures_sprite_button \ textures/textures_sprite_explosion \ textures/textures_bunnymark \ textures/textures_blend_modes \ textures/textures_draw_tiled \ - textures/textures_polygon + textures/textures_polygon \ + textures/textures_gif_anim TEXT = \ text/text_raylib_fonts \ diff --git a/examples/Makefile.Web b/examples/Makefile.Web index 9d27443d..9765a2ff 100644 --- a/examples/Makefile.Web +++ b/examples/Makefile.Web @@ -427,7 +427,6 @@ SHAPES = \ TEXTURES = \ textures/textures_logo_raylib \ textures/textures_mouse_painting \ - textures/textures_rectangle \ textures/textures_srcrec_dstrec \ textures/textures_image_drawing \ textures/textures_image_generation \ @@ -439,6 +438,7 @@ TEXTURES = \ textures/textures_particles_blending \ textures/textures_npatch_drawing \ textures/textures_background_scrolling \ + textures/textures_sprite_anim \ textures/textures_sprite_button \ textures/textures_sprite_explosion \ textures/textures_bunnymark \ @@ -659,7 +659,7 @@ textures/textures_logo_raylib: textures/textures_logo_raylib.c textures/textures_mouse_painting: textures/textures_mouse_painting.c $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) -textures/textures_rectangle: textures/textures_rectangle.c +textures/textures_sprite_anim: textures/textures_sprite_anim.c $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \ --preload-file textures/resources/scarfy.png@resources/scarfy.png diff --git a/examples/README.md b/examples/README.md index 15ccfc25..6fb65514 100644 --- a/examples/README.md +++ b/examples/README.md @@ -77,7 +77,6 @@ Examples using raylib textures functionality, including image/textures loading/g | ## | example | image | developer | new | |----|---------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------|:------------------------------------------------:|:---:| | 40 | [textures_logo_raylib](textures/textures_logo_raylib.c) | textures_logo_raylib | ray | | -| 41 | [textures_rectangle](textures/textures_rectangle.c) | textures_rectangle | ray | | | 42 | [textures_srcrec_dstrec](textures/textures_srcrec_dstrec.c) | textures_srcrec_dstrec | ray | | | 43 | [textures_image_drawing](textures/textures_image_drawing.c) | textures_image_drawing | ray | | | 44 | [textures_image_generation](textures/textures_image_generation.c) | textures_image_generation | ray | | @@ -89,6 +88,7 @@ Examples using raylib textures functionality, including image/textures loading/g | 50 | [textures_particles_blending](textures/textures_particles_blending.c) | textures_particles_blending | ray | | | 51 | [textures_npatch_drawing](textures/textures_npatch_drawing.c) | textures_npatch_drawing | [Jorge A. Gomes](https://github.com/overdev) | | | 52 | [textures_background_scrolling](textures/textures_background_scrolling.c) | textures_background_scrolling | ray | | +| 41 | [textures_sprite_anim](textures/textures_sprite_anim.c) | textures_sprite_anim | ray | | | 53 | [textures_sprite_button](textures/textures_sprite_button.c) | textures_sprite_button | ray | | | 54 | [textures_sprite_explosion](textures/textures_sprite_explosion.c) | textures_sprite_explosion | ray | | | 55 | [textures_bunnymark](textures/textures_bunnymark.c) | textures_bunnymark | ray | | @@ -96,6 +96,8 @@ Examples using raylib textures functionality, including image/textures loading/g | 57 | [textures_blend_modes](textures/textures_blend_modes.c) | textures_blend_modes | [Karlo Licudine](https://github.com/accidentalrebel) | | | 58 | [textures_draw_tiled](textures/textures_draw_tiled.c) | textures_draw_tiled | [Vlad Adrian](https://github.com/demizdor) | | | -- | [textures_poly](textures/textures_poly.c) | textures_poly | [Chris Camacho](https://github.com/codifies) | ⭐️ | +| -- | [textures_gif_anim](textures/textures_gif_anim.c) | textures_gif_anim | [Chris Camacho](https://github.com/codifies) | ⭐️ | + ### category: text diff --git a/examples/textures/textures_rectangle.c b/examples/textures/textures_rectangle.c deleted file mode 100644 index eb9f818b..00000000 --- a/examples/textures/textures_rectangle.c +++ /dev/null @@ -1,102 +0,0 @@ -/******************************************************************************************* -* -* raylib [textures] example - Texture loading and drawing a part defined by a rectangle -* -* This example has been created using raylib 1.3 (www.raylib.com) -* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) -* -* Copyright (c) 2014 Ramon Santamaria (@raysan5) -* -********************************************************************************************/ - -#include "raylib.h" - -#define MAX_FRAME_SPEED 15 -#define MIN_FRAME_SPEED 1 - -//------------------------------------------------------------------------------------ -// Program main entry point -//------------------------------------------------------------------------------------ -int main(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const int screenHeight = 450; - - InitWindow(screenWidth, screenHeight, "raylib [texture] example - texture rectangle"); - - // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) - Texture2D scarfy = LoadTexture("resources/scarfy.png"); // Texture loading - - Vector2 position = { 350.0f, 280.0f }; - Rectangle frameRec = { 0.0f, 0.0f, (float)scarfy.width/6, (float)scarfy.height }; - int currentFrame = 0; - - int framesCounter = 0; - int framesSpeed = 8; // Number of spritesheet frames shown by second - - SetTargetFPS(60); // Set our game to run at 60 frames-per-second - //-------------------------------------------------------------------------------------- - - // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key - { - // Update - //---------------------------------------------------------------------------------- - framesCounter++; - - if (framesCounter >= (60/framesSpeed)) - { - framesCounter = 0; - currentFrame++; - - if (currentFrame > 5) currentFrame = 0; - - frameRec.x = (float)currentFrame*(float)scarfy.width/6; - } - - if (IsKeyPressed(KEY_RIGHT)) framesSpeed++; - else if (IsKeyPressed(KEY_LEFT)) framesSpeed--; - - if (framesSpeed > MAX_FRAME_SPEED) framesSpeed = MAX_FRAME_SPEED; - else if (framesSpeed < MIN_FRAME_SPEED) framesSpeed = MIN_FRAME_SPEED; - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - DrawTexture(scarfy, 15, 40, WHITE); - DrawRectangleLines(15, 40, scarfy.width, scarfy.height, LIME); - DrawRectangleLines(15 + (int)frameRec.x, 40 + (int)frameRec.y, (int)frameRec.width, (int)frameRec.height, RED); - - DrawText("FRAME SPEED: ", 165, 210, 10, DARKGRAY); - DrawText(TextFormat("%02i FPS", framesSpeed), 575, 210, 10, DARKGRAY); - DrawText("PRESS RIGHT/LEFT KEYS to CHANGE SPEED!", 290, 240, 10, DARKGRAY); - - for (int i = 0; i < MAX_FRAME_SPEED; i++) - { - if (i < framesSpeed) DrawRectangle(250 + 21*i, 205, 20, 20, RED); - DrawRectangleLines(250 + 21*i, 205, 20, 20, MAROON); - } - - DrawTextureRec(scarfy, frameRec, position, WHITE); // Draw part of the texture - - DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth - 200, screenHeight - 20, 10, GRAY); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - UnloadTexture(scarfy); // Texture unloading - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -} \ No newline at end of file diff --git a/examples/textures/textures_rectangle.png b/examples/textures/textures_rectangle.png deleted file mode 100644 index aa66464e..00000000 Binary files a/examples/textures/textures_rectangle.png and /dev/null differ diff --git a/examples/textures/textures_sprite_anim.c b/examples/textures/textures_sprite_anim.c new file mode 100644 index 00000000..0e66b883 --- /dev/null +++ b/examples/textures/textures_sprite_anim.c @@ -0,0 +1,103 @@ +/******************************************************************************************* +* +* raylib [textures] example - Sprite animation +* +* This example has been created using raylib 1.3 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2014 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#define MAX_FRAME_SPEED 15 +#define MIN_FRAME_SPEED 1 + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [texture] example - sprite anim"); + + // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) + Texture2D scarfy = LoadTexture("resources/scarfy.png"); // Texture loading + + Vector2 position = { 350.0f, 280.0f }; + Rectangle frameRec = { 0.0f, 0.0f, (float)scarfy.width/6, (float)scarfy.height }; + int currentFrame = 0; + + int framesCounter = 0; + int framesSpeed = 8; // Number of spritesheet frames shown by second + + SetTargetFPS(60); // Set our game to run at 60 frames-per-second + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + framesCounter++; + + if (framesCounter >= (60/framesSpeed)) + { + framesCounter = 0; + currentFrame++; + + if (currentFrame > 5) currentFrame = 0; + + frameRec.x = (float)currentFrame*(float)scarfy.width/6; + } + + // Control frames speed + if (IsKeyPressed(KEY_RIGHT)) framesSpeed++; + else if (IsKeyPressed(KEY_LEFT)) framesSpeed--; + + if (framesSpeed > MAX_FRAME_SPEED) framesSpeed = MAX_FRAME_SPEED; + else if (framesSpeed < MIN_FRAME_SPEED) framesSpeed = MIN_FRAME_SPEED; + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawTexture(scarfy, 15, 40, WHITE); + DrawRectangleLines(15, 40, scarfy.width, scarfy.height, LIME); + DrawRectangleLines(15 + (int)frameRec.x, 40 + (int)frameRec.y, (int)frameRec.width, (int)frameRec.height, RED); + + DrawText("FRAME SPEED: ", 165, 210, 10, DARKGRAY); + DrawText(TextFormat("%02i FPS", framesSpeed), 575, 210, 10, DARKGRAY); + DrawText("PRESS RIGHT/LEFT KEYS to CHANGE SPEED!", 290, 240, 10, DARKGRAY); + + for (int i = 0; i < MAX_FRAME_SPEED; i++) + { + if (i < framesSpeed) DrawRectangle(250 + 21*i, 205, 20, 20, RED); + DrawRectangleLines(250 + 21*i, 205, 20, 20, MAROON); + } + + DrawTextureRec(scarfy, frameRec, position, WHITE); // Draw part of the texture + + DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth - 200, screenHeight - 20, 10, GRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(scarfy); // Texture unloading + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} \ No newline at end of file diff --git a/examples/textures/textures_sprite_anim.png b/examples/textures/textures_sprite_anim.png new file mode 100644 index 00000000..aa66464e Binary files /dev/null and b/examples/textures/textures_sprite_anim.png differ -- cgit v1.2.3