BatchgifToSpriteSheet.c 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // !! needs files 0x.gif to 09.gif in the same folder as this example.
  2. //
  3. //
  4. // gif to sprite sheet Script (work in progress)
  5. //
  6. // I had some sprites that needed converting. I have a folder filled with
  7. // gif files. Each gif file is a tiny sprite. They are named 01..99+.gif
  8. // I wanted to load each of these gifs and make a sprite sheet of them and then
  9. // save this sheet as a image file.
  10. //
  11. // I was working on doing this but discovered the export function of the
  12. // tool I used had a bug where only the first sprite of a set was saved as
  13. // a gif. I decided not to continue at this point.
  14. // What I have here is a loader that creates x amount of textures. Then
  15. // the loadtexture command loads the first 10 of these gifs into
  16. // this array. It shows how to create a load function which can load
  17. // procedural generated filenames.
  18. #include "raylib.h"
  19. #include <string.h>
  20. // create the container for the gifs
  21. Texture2D im[150];
  22. int main(void)
  23. {
  24. // Initialization
  25. //--------------------------------------------------------------------------------------
  26. const int screenWidth = 800;
  27. const int screenHeight = 450;
  28. InitWindow(screenWidth, screenHeight, "raylib example.");
  29. // create our char that wil contain the filename.
  30. char lfn[6]; // '0x.gif'
  31. // create the first set of names
  32. for(int i=1;i<10;i++){
  33. lfn[0] = 0;
  34. lfn[1] = i; // here we add the number in the filename
  35. lfn[2] = '.'; // gif extension
  36. lfn[3] = 'g';
  37. lfn[4] = 'i';
  38. lfn[5] = 'f';
  39. // load the texture using the FormatText command
  40. im[i] = LoadTexture(FormatText("0%i.gif",i));
  41. }
  42. //im1 = LoadTexture("01.gif"); // test case
  43. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  44. //--------------------------------------------------------------------------------------
  45. //im1 = LoadTexture(lfn);
  46. //DrawTexture(im1, 190+i*16, 190, WHITE);
  47. // Main game loop
  48. while (!WindowShouldClose()) // Detect window close button or ESC key
  49. {
  50. // Update
  51. //----------------------------------------------------------------------------------
  52. //----------------------------------------------------------------------------------
  53. // Draw
  54. //----------------------------------------------------------------------------------
  55. BeginDrawing();
  56. // draw the texture(gifs) on the canvas
  57. int cnt=0;
  58. for(int y=0;y<10;y++){
  59. for(int x=0;x<20;x++){
  60. if(cnt<10){
  61. DrawTexture(im[cnt],x*16,y*16,WHITE);
  62. }
  63. cnt++;
  64. }}
  65. // test case
  66. //DrawText(lfn,100,80,20,BLACK);
  67. //DrawText(FormatText("0%i.gif",i),100,80,20,BLACK);
  68. ClearBackground(RAYWHITE);
  69. EndDrawing();
  70. //----------------------------------------------------------------------------------
  71. }
  72. for(int i=0;i<50;i++){
  73. UnloadTexture(im[i]);
  74. }
  75. // De-Initialization
  76. //--------------------------------------------------------------------------------------
  77. CloseWindow(); // Close window and OpenGL context
  78. //--------------------------------------------------------------------------------------
  79. return 0;
  80. }