distorted text
Posted: Mon Jun 24, 2013 4:05 am
When i draw any text i see it distorted, sometimes more, sometimes less, it's kinda unstable, as i have only 2 files in my game i'll copy and paste it here instead of creating a .love file:
main.lua
game.lua:
Screenshot:
main.lua
Code: Select all
require('game')
function love.load()
love.graphics.setMode(800, 600)
game.state = 'intro'
game.statemanager[game.state].firstdraw = true
love.graphics.setBackgroundColor(0, 0, 0)
end
function love.update(dt)
end
function love.keypressed(key, unicode)
if key == 'escape' then
love.event.quit()
elseif key == 'f1' then
love.graphics.toggleFullscreen()
end
end
function love.draw()
if game.statemanager[game.state].firstdraw then
game.statemanager.draw()
game.statemanager[game.state].firstdraw = false
elseif game.statemanager[game.state].firstdraw == false and game.statemanager[game.state].update then
game.statemanager.updateScene()
else
game.statemanager.redraw()
end
end
Code: Select all
-- Game main array
game = {}
game.state = ''
menuText = love.graphics.newFont('tahoma.ttf', 24)
-- State manager
game.statemanager = {}
game.statemanager['intro'] = {}
game.statemanager['intro'].firstdraw = nil
game.statemanager['intro'].update = nil
game.statemanager['current'] = {}
game.statemanager['current'].texts = {}
game.statemanager['current'].images = {}
-- Default to 'current'.texts array:
-- .font = fontObject [object taken from newFont constructor]
-- .color = {r = 255, g = 255, b = 255, a = 255} [red, green, blue and alpha values]
-- .text = 'my text' [the text to write]
-- .pos = {x, y}
-- Default to 'current'.images array:
-- .src = imageObject [object taken from newImage constructor]
-- .pos = {x, y} [z already taken from array position]
function game.statemanager.draw()
if game.state == 'intro' then
love.graphics.setFont(menuText)
love.graphics.setColor(255, 255, 255, 255)
love.graphics.print('New Game', 350, 300)
love.graphics.print('Load Game', 350, 330)
table.insert(game.statemanager['current'].texts, {font = menuText, color = {r = 255, g = 255, b =255, a = 255}, text = 'New Game', pos = {350, 300}})
table.insert(game.statemanager['current'].texts, {font = menuText, color = {r = 255, g = 255, b =255, a = 255}, text = 'Load Game', pos = {350, 330}})
end
end
function game.statemanager.redraw()
for k,v in pairs(game.statemanager['current'].images) do
-- to do
end
for k,v in pairs(game.statemanager['current'].texts) do
love.graphics.setFont(v.font)
love.graphics.setColor(v.color.r, v.color.g, v.color.b, v.color.a)
love.graphics.print(v.text, v.pos[1], v.pos[2])
end
end
function game.statemanager.updateScene()
end