diff options
| author | raysan5 <raysan5@gmail.com> | 2015-08-28 14:16:28 +0200 |
|---|---|---|
| committer | raysan5 <raysan5@gmail.com> | 2015-08-28 14:16:28 +0200 |
| commit | ca402e9d360d519e37e2fb1d8073ebec56b0014c (patch) | |
| tree | f5b0c858c49e794add2006a1cc8ec094f1a0a950 /examples/textures_rectangle.c | |
| parent | 6ac5d3bc06913469f6e32f68a4c356e1c1da24b8 (diff) | |
| download | raylib-ca402e9d360d519e37e2fb1d8073ebec56b0014c.tar.gz raylib-ca402e9d360d519e37e2fb1d8073ebec56b0014c.zip | |
New examples added (with some resources)
Diffstat (limited to 'examples/textures_rectangle.c')
| -rw-r--r-- | examples/textures_rectangle.c | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/examples/textures_rectangle.c b/examples/textures_rectangle.c index c0fb0d97..61cce9fb 100644 --- a/examples/textures_rectangle.c +++ b/examples/textures_rectangle.c @@ -5,7 +5,7 @@ * This example has been created using raylib 1.0 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * -* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* Copyright (c) 2014 Ramon Santamaria (@raysan5) * ********************************************************************************************/ @@ -20,15 +20,12 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [texture] example - texture rectangle"); - const char textLine1[] = "Lena image is a standard test image which has been in use since 1973."; - const char textLine2[] = "It comprises 512x512 pixels, and it is probably the most widely used"; - const char textLine3[] = "test image for all sorts of image processing algorithms."; - // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) - Texture2D texture = LoadTexture("resources/lena.png"); // Texture loading + Texture2D guybrush = LoadTexture("resources/guybrush.png"); // Texture loading - Rectangle eyesRec = { 225, 240, 155, 50 }; // Part of the texture to draw - Vector2 position = { 369, 241 }; + Vector2 position = { 350, 240 }; + Rectangle frameRec = { 0, 0, guybrush.width/7, guybrush.height }; + int currentFrame = 0; //-------------------------------------------------------------------------------------- // Main game loop @@ -36,7 +33,14 @@ int main() { // Update //---------------------------------------------------------------------------------- - // TODO: Update your variables here + if (IsKeyPressed(KEY_RIGHT)) + { + currentFrame++; + + if (currentFrame > 6) currentFrame = 0; + + frameRec.x = currentFrame*guybrush.width/7; + } //---------------------------------------------------------------------------------- // Draw @@ -45,15 +49,19 @@ int main() ClearBackground(RAYWHITE); - DrawText("LENA", 220, 100, 20, PINK); - - DrawTexture(texture, screenWidth/2 - 256, 0, Fade(WHITE, 0.1f)); // Draw background image - - DrawTextureRec(texture, eyesRec, position, WHITE); // Draw eyes part of image - - DrawText(textLine1, 220, 140, 10, DARKGRAY); - DrawText(textLine2, 220, 160, 10, DARKGRAY); - DrawText(textLine3, 220, 180, 10, DARKGRAY); + DrawTexture(guybrush, 35, 40, WHITE); + DrawRectangleLines(35, 40, guybrush.width, guybrush.height, LIME); + + DrawTextureRec(guybrush, frameRec, position, WHITE); // Draw part of the texture + + DrawRectangleLines(35 + frameRec.x, 40 + frameRec.y, frameRec.width, frameRec.height, RED); + + DrawText("PRESS RIGHT KEY to", 540, 310, 10, GRAY); + DrawText("CHANGE DRAWING RECTANGLE", 520, 330, 10, GRAY); + + 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); EndDrawing(); //---------------------------------------------------------------------------------- @@ -61,7 +69,7 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - UnloadTexture(texture); // Texture unloading + UnloadTexture(guybrush); // Texture unloading CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- |
