distorted text

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
batatinha
Prole
Posts: 22
Joined: Mon Jun 24, 2013 3:49 am

distorted text

Post by batatinha »

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

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
game.lua:

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
Screenshot:
Image
User avatar
MadByte
Party member
Posts: 533
Joined: Fri May 03, 2013 6:42 pm
Location: Braunschweig, Germany

Re: distorted text

Post by MadByte »

It does look like the Font file is corrupted or something because only the "e" looks bad.
You meight want to check this.
batatinha
Prole
Posts: 22
Joined: Mon Jun 24, 2013 3:49 am

Re: distorted text

Post by batatinha »

Thank you, it's running fine now...
I just got another problem, i was playing with the particles system just to see how it works, but i can't see anything, i even did some prints to see how many particles there is running and everything seems ok...

I didn't find any example/tutorial about this, so i'm probably doing something really wrong...

Code: Select all

require('game')
mouseEffect = nil
particle1 = nil

function love.load()
	love.graphics.setMode(800, 600)
	game.state = 'intro'
	game.statemanager[game.state].firstdraw = true
	love.graphics.setBackgroundColor(0, 0, 0)
	particle1 = love.graphics.newImage('graphics/particles/1.png')
	mouseEffect = love.graphics.newParticleSystem(particle1, 1000)
	mouseEffect:setColors(255, 255, 150, 10, 150, 200, 255, 50, 10, 200, 255, 100)
	mouseEffect:setDirection(360)
	mouseEffect:setEmissionRate(100)
	mouseEffect:setGravity(0)
	mouseEffect:setLifetime(-1)
	mouseEffect:setSizes(0.1, 0.2, 0.3)
	mouseEffect:setParticleLife(0.1, 1)
	mouseEffect:setSpeed(5, 10)
	mouseEffect:setSpread(360)
	mx, my = love.mouse.getPosition()
	mouseEffect:setOffset(mx/2, my/2)
	mouseEffect:setPosition(mx+10, my+20)
	mouseEffect:start()
end

function love.update(dt)
	mx, my = love.mouse.getPosition()
	if mouseEffect:isActive() and mx ~= mouseEffect:getOffsetX() and my ~= mouseEffect:getOffsetY() then
		mouseEffect:setOffset(mx/2, my/2)
		mouseEffect:setPosition(mx+10, my+20)
		mouseEffect:update(dt)
	else
		mouseEffect:update(dt)
	end
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
	love.graphics.draw(mouseEffect, 0, 0)
	love.graphics.print('Particles: '.. mouseEffect:count(), 10, 10)
end
Also, before that code i was doing the start() function in the load and update() function without any filters and the particles varies from 140~150, after that, the particles grows in number when i move the mouse, but never more than 150, it's really weird...

edit: fix'd
Last edited by batatinha on Mon Jun 24, 2013 8:05 am, edited 1 time in total.
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: distorted text

Post by Plu »

I think you still have to add a draw call to your particle system to put it on screen :)

Code: Select all

love.graphics.draw( mouseEffect )
batatinha
Prole
Posts: 22
Joined: Mon Jun 24, 2013 3:49 am

Re: distorted text

Post by batatinha »

Yes, already solved that, u posted exactly when i edited the thread... :3
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 28 guests