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_srcrec_dstrec.c | |
| parent | 6ac5d3bc06913469f6e32f68a4c356e1c1da24b8 (diff) | |
| download | raylib-ca402e9d360d519e37e2fb1d8073ebec56b0014c.tar.gz raylib-ca402e9d360d519e37e2fb1d8073ebec56b0014c.zip | |
New examples added (with some resources)
Diffstat (limited to 'examples/textures_srcrec_dstrec.c')
| -rw-r--r-- | examples/textures_srcrec_dstrec.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/examples/textures_srcrec_dstrec.c b/examples/textures_srcrec_dstrec.c index 1f0b56e2..72a209fb 100644 --- a/examples/textures_srcrec_dstrec.c +++ b/examples/textures_srcrec_dstrec.c @@ -5,7 +5,7 @@ * This example has been created using raylib 1.1 (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) * ********************************************************************************************/ @@ -21,16 +21,23 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [textures] examples - texture source and destination rectangles"); // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) - Texture2D texture = LoadTexture("resources/raylib_logo.png"); // Texture loading + Texture2D guybrush = LoadTexture("resources/guybrush.png"); // Texture loading + int frameWidth = guybrush.width/7; + int frameHeight = guybrush.height; + // NOTE: Source rectangle (part of the texture to use for drawing) - Rectangle sourceRec = { 128, 128, 128, 128 }; + Rectangle sourceRec = { 0, 0, frameWidth, frameHeight }; // NOTE: Destination rectangle (screen rectangle where drawing part of texture) - Rectangle destRec = { screenWidth/2, screenHeight/2, 256, 256 }; - - // NOTE: Origin of the texture in case of rotation, it's relative to destination rectangle size - Vector2 origin = { 128, 128 }; + Rectangle destRec = { screenWidth/2, screenHeight/2, frameWidth*2, frameHeight*2 }; + + // NOTE: Origin of the texture (rotation/scale point), it's relative to destination rectangle size + Vector2 origin = { frameWidth, frameHeight }; + + int rotation = 0; + + SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop @@ -38,7 +45,7 @@ int main() { // Update //---------------------------------------------------------------------------------- - // TODO: Update your variables here + rotation++; //---------------------------------------------------------------------------------- // Draw @@ -48,10 +55,10 @@ int main() ClearBackground(RAYWHITE); // NOTE: Using DrawTexturePro() we can easily rotate and scale the part of the texture we draw - DrawTexturePro(texture, sourceRec, destRec, origin, 45, LIGHTGRAY); + DrawTexturePro(guybrush, sourceRec, destRec, origin, rotation, WHITE); - DrawLine(destRec.x, 0, destRec.x, screenHeight, RED); - DrawLine(0, destRec.y, screenWidth, destRec.y, RED); + DrawLine(destRec.x, 0, destRec.x, screenHeight, GRAY); + DrawLine(0, destRec.y, screenWidth, destRec.y, GRAY); EndDrawing(); //---------------------------------------------------------------------------------- @@ -59,7 +66,7 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - UnloadTexture(texture); // Texture unloading + UnloadTexture(guybrush); // Texture unloading CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- |
