Page 1 of 1

how i can do this with setColor()

Posted: Tue Sep 15, 2015 9:06 pm
by vitail
i want to print a text with a black color but if i want to restore the colors for the sprites(to keep the original colors) how i can do this with love.graphics.setColor(r,g,b,a)???

Code: Select all

function love.draw()
	love.graphics.setColor(0,0,0,100)
	love.graphics.setFont(mainFont) -- select the main font
	love.graphics.print("Score: " .. tostring(score), _WIDTH, _HEIGHT) -- print score and 
	love.graphics.print("Lives: " .. tostring(lives), _WIDTH, _HEIGHT + (64)) -- lives on the screen
        --HOW I CAN RESTORE THE COLORS FOR THE SPRITES.
	--Draw stuff
	love.graphics.draw(bg.img, 0, 0);

	for i,bullet in ipairs(bullets) do
		love.graphics.draw(bullet.img,bullet.x,bullet.y)
	end

	for i, enemy in ipairs(enemies) do
		love.graphics.draw(enemy.img,enemy.x,enemy.y)	
	end

	if isAlive then
		love.graphics.draw(player.img, player.x - (player.w / 2), player.y - (player.h / 2) )	
	end

	
end

Re: how i can do this with setColor()

Posted: Tue Sep 15, 2015 9:07 pm
by MadByte
Just set the color back to white.

Code: Select all

love.graphics.setColor(255, 255, 255, 255)

Re: how i can do this with setColor()

Posted: Tue Sep 15, 2015 9:25 pm
by vitail
MadByte wrote:Just set the color back to white.

Code: Select all

love.graphics.setColor(255, 255, 255, 255)
nice, thanks

and now why don't draw the love.graphics.print?

Code: Select all

	love.graphics.draw(bg.img, 0, 0);

	love.graphics.setColor(0,0,0,255)
	
	love.graphics.setFont(mainFont) -- select the main font

	love.graphics.print("Score: " .. tostring(score), _WIDTH, _HEIGHT) -- print score and 
	love.graphics.print("Lives: " .. tostring(lives), _WIDTH, _HEIGHT + (64)) -- lives on the screen
	
	love.graphics.setColor(255,255,255,255)
i loaded the font and this dont work

Code: Select all

function love.load()
	--Load assets
	bg.img = love.graphics.newImage('assets/bg.png')
	player.img = love.graphics.newImage('assets/spr_player.png')
	bulletImg = love.graphics.newImage('assets/spr_bullet.png')
	enemyImg = love.graphics.newImage('assets/spr_enemy.png')

	inGameFont = love.graphics.newFont("assets/8BIT WONDER.ttf", 100);
end

Re: how i can do this with setColor()

Posted: Tue Sep 15, 2015 10:23 pm
by davisdude
Alternatively, to store all previous graphics states, you can do this:

Code: Select all

function love.draw()
   love.graphics.push( 'all' )
      love.graphics.setColor(0,0,0,100)
      love.graphics.setFont(mainFont) -- select the main font
      love.graphics.print("Score: " .. tostring(score), _WIDTH, _HEIGHT) -- print score and 
      love.graphics.print("Lives: " .. tostring(lives), _WIDTH, _HEIGHT + (64)) -- lives on the screen
   love.graphics.pop()
   --Draw stuff
   love.graphics.draw(bg.img, 0, 0);
   -- etc. ...
end
Also, it's probably not drawing the text because you're drawing bg.img over the text- try reversing the order and see what happens.