aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorRay <raysan5@gmail.com>2017-04-07 00:51:08 +0200
committerRay <raysan5@gmail.com>2017-04-07 00:51:08 +0200
commit29067e19d9fd261c9e927eec07bfcb92bc8ab370 (patch)
tree871af4bf9f8b706827eac3c1c9a360b1b1b71eca /examples
parent74255b6eb2584c272ff647cfbac1cdceceb1965f (diff)
downloadraylib-29067e19d9fd261c9e927eec07bfcb92bc8ab370.tar.gz
raylib-29067e19d9fd261c9e927eec07bfcb92bc8ab370.zip
Redesigned textures_rectangle example
Diffstat (limited to 'examples')
-rw-r--r--examples/textures/resources/guybrush.pngbin85247 -> 0 bytes
-rw-r--r--examples/textures/resources/heightmap.pngbin10920 -> 0 bytes
-rw-r--r--examples/textures/resources/scarfy.pngbin0 -> 21597 bytes
-rw-r--r--examples/textures/textures_rectangle.c55
-rw-r--r--examples/textures/textures_rectangle.pngbin109993 -> 39809 bytes
5 files changed, 38 insertions, 17 deletions
diff --git a/examples/textures/resources/guybrush.png b/examples/textures/resources/guybrush.png
deleted file mode 100644
index 32c9dced..00000000
--- a/examples/textures/resources/guybrush.png
+++ /dev/null
Binary files differ
diff --git a/examples/textures/resources/heightmap.png b/examples/textures/resources/heightmap.png
deleted file mode 100644
index fe30f679..00000000
--- a/examples/textures/resources/heightmap.png
+++ /dev/null
Binary files differ
diff --git a/examples/textures/resources/scarfy.png b/examples/textures/resources/scarfy.png
new file mode 100644
index 00000000..a377a712
--- /dev/null
+++ b/examples/textures/resources/scarfy.png
Binary files differ
diff --git a/examples/textures/textures_rectangle.c b/examples/textures/textures_rectangle.c
index cca5b216..c90db8ac 100644
--- a/examples/textures/textures_rectangle.c
+++ b/examples/textures/textures_rectangle.c
@@ -11,6 +11,9 @@
#include "raylib.h"
+#define MAX_FRAME_SPEED 15
+#define MIN_FRAME_SPEED 1
+
int main()
{
// Initialization
@@ -21,11 +24,16 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [texture] example - texture rectangle");
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
- Texture2D guybrush = LoadTexture("resources/guybrush.png"); // Texture loading
+ Texture2D scarfy = LoadTexture("resources/scarfy.png"); // Texture loading
- Vector2 position = { 350.0f, 240.0f };
- Rectangle frameRec = { 0, 0, guybrush.width/7, guybrush.height };
+ Vector2 position = { 350.0f, 280.0f };
+ Rectangle frameRec = { 0, 0, scarfy.width/6, 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
@@ -33,14 +41,23 @@ int main()
{
// Update
//----------------------------------------------------------------------------------
- if (IsKeyPressed(KEY_RIGHT))
+ framesCounter++;
+
+ if (framesCounter >= (60/framesSpeed))
{
+ framesCounter = 0;
currentFrame++;
- if (currentFrame > 6) currentFrame = 0;
+ if (currentFrame > 5) currentFrame = 0;
- frameRec.x = currentFrame*guybrush.width/7;
+ frameRec.x = currentFrame*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
@@ -49,19 +66,23 @@ int main()
ClearBackground(RAYWHITE);
- DrawTexture(guybrush, 35, 40, WHITE);
- DrawRectangleLines(35, 40, guybrush.width, guybrush.height, LIME);
-
- DrawTextureRec(guybrush, frameRec, position, WHITE); // Draw part of the texture
+ DrawTexture(scarfy, 15, 40, WHITE);
+ DrawRectangleLines(15, 40, scarfy.width, scarfy.height, LIME);
+ DrawRectangleLines(15 + frameRec.x, 40 + frameRec.y, frameRec.width, frameRec.height, RED);
- DrawRectangleLines(35 + frameRec.x, 40 + frameRec.y, frameRec.width, frameRec.height, RED);
+ DrawText("FRAME SPEED: ", 165, 210, 10, DARKGRAY);
+ DrawText(FormatText("%02i FPS", framesSpeed), 575, 210, 10, DARKGRAY);
+ DrawText("PRESS RIGHT/LEFT KEYS to CHANGE SPEED!", 290, 240, 10, DARKGRAY);
- DrawText("PRESS RIGHT KEY to", 540, 310, 10, GRAY);
- DrawText("CHANGE DRAWING RECTANGLE", 520, 330, 10, GRAY);
+ 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);
+ }
- DrawText("Guybrush Ulysses Threepwood,", 100, 300, 10, GRAY);
- DrawText("main character of the Monkey Island series", 80, 320, 10, GRAY);
- DrawText("of computer adventure games by LucasArts.", 80, 340, 10, GRAY);
+ DrawTextureRec(scarfy, frameRec, position, WHITE); // Draw part of the texture
+
+ DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth - 200, screenHeight - 20, 10, GRAY);
EndDrawing();
//----------------------------------------------------------------------------------
@@ -69,7 +90,7 @@ int main()
// De-Initialization
//--------------------------------------------------------------------------------------
- UnloadTexture(guybrush); // Texture unloading
+ UnloadTexture(scarfy); // Texture unloading
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
diff --git a/examples/textures/textures_rectangle.png b/examples/textures/textures_rectangle.png
index d89404ab..aa66464e 100644
--- a/examples/textures/textures_rectangle.png
+++ b/examples/textures/textures_rectangle.png
Binary files differ