Skip to content

Commit

Permalink
Don't recreate fonts with every draw, reduces memory
Browse files Browse the repository at this point in the history
  • Loading branch information
TomK32 committed Dec 4, 2012
1 parent ad0fa14 commit 0c97a04
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions main.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- (C) 2012 Thomas R. Koll, <info@ananasblau.com>
-- Fortress Middle Management Services
-- Cross Country Runner
require("lib/middleclass")
require('table')
require('entities/runner')
Expand All @@ -16,10 +16,11 @@ require('job_spawner')
function love.load()
game_state = GameState()
gui_main = GUIMain(game_state)
gui_main.font = love.graphics.newFont(14)
gui_main.small_font = love.graphics.newFont(10)
game_controller = GameController(game_state, gui_main)
dt_since_last_move = 1
end

function love.update(dt)
local moved = false
if game_state.focus == 'inspector' or game_state.focus == 'main' then
Expand Down Expand Up @@ -78,15 +79,19 @@ function love.draw()
love.graphics.clear()
gui_main:draw()
love.graphics.setColor(255,255,255,255)
love.graphics.setFont(love.graphics.newFont(14))
love.graphics.setFont(gui_main.font)
if game_state.paused then
love.graphics.print('PAUSED', 10, 20)
else
love.graphics.print("FPS: "..love.timer.getFPS(), 10, 20)
end
love.graphics.setFont(love.graphics.newFont(10))
drawCopyright()
end

function drawCopyright()
love.graphics.setFont(gui_main.small_font)
love.graphics.print(love.graphics.getCaption(), love.graphics.getWidth(), love.graphics.getHeight(), 0, 1, 1, 176, 14)
love.graphics.setFont(love.graphics.newFont(14))
love.graphics.setFont(gui_main.font)
end

function finishScreen()
Expand Down

0 comments on commit 0c97a04

Please sign in to comment.