Add an example of the bitmap fonts
This commit is contained in:
parent
ee4762673a
commit
cf06bdce64
2 changed files with 20 additions and 4 deletions
BIN
game/font.png
Normal file
BIN
game/font.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
|
|
@ -4,21 +4,37 @@ if love.system.getOS() ~= 'DOS' then
|
||||||
end
|
end
|
||||||
|
|
||||||
local platform = require "platform.platform"
|
local platform = require "platform.platform"
|
||||||
|
local ttf
|
||||||
function love.load()
|
local bf
|
||||||
platform.init()
|
local bfi
|
||||||
end
|
|
||||||
|
|
||||||
local function drawText(str, x, y)
|
local function drawText(str, x, y)
|
||||||
local font = love.graphics.getFont()
|
local font = love.graphics.getFont()
|
||||||
love.graphics.print(str, x - font:getWidth(str) / 2, y - font:getHeight() / 2)
|
love.graphics.print(str, x - font:getWidth(str) / 2, y - font:getHeight() / 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function love.load()
|
||||||
|
platform.init()
|
||||||
|
|
||||||
|
ttf = love.graphics.newFont()
|
||||||
|
bf = love.graphics.newImageFont("font.png",
|
||||||
|
" abcdefghijklmnopqrstuvwxyz" ..
|
||||||
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0" ..
|
||||||
|
"123456789.,!?-+/():;%&`'*#=[]\"")
|
||||||
|
bfi = love.graphics.newImage("font.png")
|
||||||
|
end
|
||||||
|
|
||||||
function love.draw()
|
function love.draw()
|
||||||
platform.drawStart()
|
platform.drawStart()
|
||||||
|
|
||||||
love.graphics.clear()
|
love.graphics.clear()
|
||||||
|
love.graphics.setFont(ttf)
|
||||||
drawText('Hellorld!', 160, 100)
|
drawText('Hellorld!', 160, 100)
|
||||||
|
love.graphics.setFont(bf)
|
||||||
|
love.graphics.print(" abcdefghijklmnopqrstuvwxyz", 0, 110)
|
||||||
|
love.graphics.print("ABCDEFGHIJKLMNOPQRSTUVWXYZ0", 0, 130)
|
||||||
|
love.graphics.print("123456789.,!?-+/():;%&`'*#=[]\"", 0, 150)
|
||||||
|
love.graphics.draw(bfi, 0, 170)
|
||||||
|
|
||||||
platform.drawEnd()
|
platform.drawEnd()
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue