Created
August 9, 2017 01:47
-
-
Save jotson/bbe63bcfa9682caccf604e819c67c1ee to your computer and use it in GitHub Desktop.
Godot Engine 2.1: Creating bitmap font from PNG image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tool | |
extends Label | |
var font | |
onready var texture = load("res://fonts/main.png") | |
func _ready(): | |
# Create font | |
font = BitmapFont.new() | |
font.add_texture(texture) | |
var pos = Vector2(0,0) | |
var size = Vector2(4, 5) | |
# A-Z | |
var char = 65 | |
for x in range(0, 26): | |
pos.x = x * size.x | |
pos.y = 0 | |
font.add_char(char, 0, Rect2(pos, size)) | |
char = char + 1 | |
# Punctuation and numbers | |
var char = 32 | |
for x in range(0, 26): | |
pos.x = x * size.x | |
pos.y = 1 * size.y | |
font.add_char(char, 0, Rect2(pos, size)) | |
char = char + 1 | |
# More punctuation | |
var char = 58 | |
for x in range(0, 7): | |
pos.x = x * size.x | |
pos.y = 2 * size.y | |
font.add_char(char, 0, Rect2(pos, size)) | |
char = char + 1 | |
add_font_override("font", font) # "font" name is magic | |
font.update_changes() | |
set_uppercase(true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment