text_font_spritefont.bmx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. SuperStrict
  2. Framework Ray.Lib
  3. ' Initialization
  4. '--------------------------------------------------------------------------------------
  5. Const screenWidth:Int = 800
  6. Const screenHeight:Int = 450
  7. InitWindow(screenWidth, screenHeight, "raylib [text] example - sprite font loading")
  8. Const msg1:String = "THIS IS A custom SPRITE FONT..."
  9. Const msg2:String = "...and this is ANOTHER CUSTOM font..."
  10. Const msg3:String = "...and a THIRD one! GREAT! :D"
  11. ' NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
  12. Local font1:RFont = LoadFont("../../lib.mod/raylib/examples/text/resources/custom_mecha.png") ' Font loading
  13. Local font2:RFont = LoadFont("../../lib.mod/raylib/examples/text/resources/custom_alagard.png") ' Font loading
  14. Local font3:RFont = LoadFont("../../lib.mod/raylib/examples/text/resources/custom_jupiter_crash.png") ' Font loading
  15. Local fontPosition1:RVector2 = New RVector2(screenWidth/2 - MeasureTextEx(font1, msg1, font1.baseSize, -3).x/2, screenHeight/2 - font1.baseSize/2 - 80)
  16. Local fontPosition2:RVector2 = New RVector2(screenWidth/2 - MeasureTextEx(font2, msg2, font2.baseSize, -2).x/2, screenHeight/2 - font2.baseSize/2 - 10)
  17. Local fontPosition3:RVector2 = New RVector2(screenWidth/2 - MeasureTextEx(font3, msg3, font3.baseSize, 2).x/2, screenHeight/2 - font3.baseSize/2 + 50)
  18. SetTargetFPS(60) ' Set our game to run at 60 frames-per-second
  19. '--------------------------------------------------------------------------------------
  20. ' Main game loop
  21. While Not WindowShouldClose() ' Detect window close button or ESC key
  22. ' Update
  23. '----------------------------------------------------------------------------------
  24. ' TODO: Update variables here...
  25. '----------------------------------------------------------------------------------
  26. ' Draw
  27. '----------------------------------------------------------------------------------
  28. BeginDrawing()
  29. ClearBackground(RAYWHITE)
  30. DrawTextEx(font1, msg1, fontPosition1, font1.baseSize, -3, WHITE)
  31. DrawTextEx(font2, msg2, fontPosition2, font2.baseSize, -2, WHITE)
  32. DrawTextEx(font3, msg3, fontPosition3, font3.baseSize, 2, WHITE)
  33. EndDrawing()
  34. '----------------------------------------------------------------------------------
  35. Wend
  36. ' De-Initialization
  37. '--------------------------------------------------------------------------------------
  38. UnloadFont(font1) ' Font unloading
  39. UnloadFont(font2) ' Font unloading
  40. UnloadFont(font3) ' Font unloading
  41. CloseWindow() ' Close window and OpenGL context
  42. '--------------------------------------------------------------------------------------