Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

77 rindas
3.1 KiB

pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
  1. /*******************************************************************************************
  2. *
  3. * raylib [textures] example - Texture loading and drawing a part defined by a rectangle
  4. *
  5. * This example has been created using raylib 1.3 (www.raylib.com)
  6. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  7. *
  8. * Copyright (c) 2014 Ramon Santamaria (@raysan5)
  9. *
  10. ********************************************************************************************/
  11. #include "raylib.h"
  12. int main()
  13. {
  14. // Initialization
  15. //--------------------------------------------------------------------------------------
  16. int screenWidth = 800;
  17. int screenHeight = 450;
  18. InitWindow(screenWidth, screenHeight, "raylib [texture] example - texture rectangle");
  19. // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
  20. Texture2D guybrush = LoadTexture("resources/guybrush.png"); // Texture loading
  21. Vector2 position = { 350.0f, 240.0f };
  22. Rectangle frameRec = { 0, 0, guybrush.width/7, guybrush.height };
  23. int currentFrame = 0;
  24. //--------------------------------------------------------------------------------------
  25. // Main game loop
  26. while (!WindowShouldClose()) // Detect window close button or ESC key
  27. {
  28. // Update
  29. //----------------------------------------------------------------------------------
  30. if (IsKeyPressed(KEY_RIGHT))
  31. {
  32. currentFrame++;
  33. if (currentFrame > 6) currentFrame = 0;
  34. frameRec.x = currentFrame*guybrush.width/7;
  35. }
  36. //----------------------------------------------------------------------------------
  37. // Draw
  38. //----------------------------------------------------------------------------------
  39. BeginDrawing();
  40. ClearBackground(RAYWHITE);
  41. DrawTexture(guybrush, 35, 40, WHITE);
  42. DrawRectangleLines(35, 40, guybrush.width, guybrush.height, LIME);
  43. DrawTextureRec(guybrush, frameRec, position, WHITE); // Draw part of the texture
  44. DrawRectangleLines(35 + frameRec.x, 40 + frameRec.y, frameRec.width, frameRec.height, RED);
  45. DrawText("PRESS RIGHT KEY to", 540, 310, 10, GRAY);
  46. DrawText("CHANGE DRAWING RECTANGLE", 520, 330, 10, GRAY);
  47. DrawText("Guybrush Ulysses Threepwood,", 100, 300, 10, GRAY);
  48. DrawText("main character of the Monkey Island series", 80, 320, 10, GRAY);
  49. DrawText("of computer adventure games by LucasArts.", 80, 340, 10, GRAY);
  50. EndDrawing();
  51. //----------------------------------------------------------------------------------
  52. }
  53. // De-Initialization
  54. //--------------------------------------------------------------------------------------
  55. UnloadTexture(guybrush); // Texture unloading
  56. CloseWindow(); // Close window and OpenGL context
  57. //--------------------------------------------------------------------------------------
  58. return 0;
  59. }