Advertisement
nezvers

Godot BitmapFont cutter

May 19th, 2021
1,259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. tool
  2. extends Label   # on preview label
  3.  
  4. export var texture:Texture  # contains
  5. export var font:BitmapFont  # saves into it if not new
  6. export var glyphSize: = Vector2(16,16)
  7. export var symbolsInTexture: = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890?!;:- '
  8.  
  9. export (bool) var cut:bool = false setget set_cut
  10. func set_cut(value:bool)->void:
  11.     if !value:
  12.         return
  13.    
  14.     update()
  15.  
  16. func update()->void:
  17.     font.clear()
  18.     var size:Vector2 = texture.get_size()
  19.     font.add_texture(texture)
  20.     font.height = glyphSize.y
  21.     var width:int = size.x / glyphSize.x
  22.     var x = 0
  23.     var y = 0
  24.     var rect = Rect2(Vector2(0.0,0.0), glyphSize)
  25.     for i in symbol_string.length():
  26.         var c = symbol_string[i]
  27.         x = i % width
  28.         y = i / width
  29.         rect.position = glyphSize * Vector2(x,y)
  30.         print(c.to_utf8()[0])
  31.         font.add_char(c.to_utf8()[0], 0, rect)
  32.    
  33.     font.update_changes()
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement