You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
3.1 KiB

  1. -------------------------------------------------------------------------------------------
  2. --
  3. -- raylib [text] example - SpriteFont loading and usage
  4. --
  5. -- This example has been created using raylib 1.6 (www.raylib.com)
  6. -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  7. --
  8. -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
  9. --
  10. -------------------------------------------------------------------------------------------
  11. -- Initialization
  12. -------------------------------------------------------------------------------------------
  13. local screenWidth = 800
  14. local screenHeight = 450
  15. InitWindow(screenWidth, screenHeight, "raylib [text] example - sprite fonts usage")
  16. local msg1 = "THIS IS A custom SPRITE FONT..."
  17. local msg2 = "...and this is ANOTHER CUSTOM font..."
  18. local msg3 = "...and a THIRD one! GREAT! :D"
  19. -- NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
  20. local font1 = LoadSpriteFont("resources/fonts/custom_mecha.png") -- SpriteFont loading
  21. local font2 = LoadSpriteFont("resources/fonts/custom_alagard.png") -- SpriteFont loading
  22. local font3 = LoadSpriteFont("resources/fonts/custom_jupiter_crash.png") -- SpriteFont loading
  23. local fontPosition1 = Vector2(0, 0)
  24. local fontPosition2 = Vector2(0, 0)
  25. local fontPosition3 = Vector2(0, 0)
  26. fontPosition1.x = screenWidth/2 - MeasureTextEx(font1, msg1, font1.size, -3).x/2
  27. fontPosition1.y = screenHeight/2 - font1.size/2 - 80
  28. fontPosition2.x = screenWidth/2 - MeasureTextEx(font2, msg2, font2.size, -2).x/2
  29. fontPosition2.y = screenHeight/2 - font2.size/2 - 10
  30. fontPosition3.x = screenWidth/2 - MeasureTextEx(font3, msg3, font3.size, 2).x/2
  31. fontPosition3.y = screenHeight/2 - font3.size/2 + 50
  32. SetTargetFPS(60) -- Set target frames-per-second
  33. -------------------------------------------------------------------------------------------
  34. -- Main game loop
  35. while not WindowShouldClose() do -- Detect window close button or ESC key
  36. -- Update
  37. ---------------------------------------------------------------------------------------
  38. -- TODO: Update variables here...
  39. ---------------------------------------------------------------------------------------
  40. -- Draw
  41. ---------------------------------------------------------------------------------------
  42. BeginDrawing()
  43. ClearBackground(RAYWHITE)
  44. DrawTextEx(font1, msg1, fontPosition1, font1.size, -3, WHITE)
  45. DrawTextEx(font2, msg2, fontPosition2, font2.size, -2, WHITE)
  46. DrawTextEx(font3, msg3, fontPosition3, font3.size, 2, WHITE)
  47. EndDrawing()
  48. ---------------------------------------------------------------------------------------
  49. end
  50. -- De-Initialization
  51. -------------------------------------------------------------------------------------------
  52. UnloadSpriteFont(font1) -- SpriteFont unloading
  53. UnloadSpriteFont(font2) -- SpriteFont unloading
  54. UnloadSpriteFont(font3) -- SpriteFont unloading
  55. CloseWindow() -- Close window and OpenGL context
  56. -------------------------------------------------------------------------------------------