how i can do this with setColor()

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
vitail
Prole
Posts: 26
Joined: Thu Apr 09, 2015 8:37 pm

how i can do this with setColor()

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

Re: how i can do this with setColor()

Post by MadByte »

Just set the color back to white.

Code: Select all

love.graphics.setColor(255, 255, 255, 255)
vitail
Prole
Posts: 26
Joined: Thu Apr 09, 2015 8:37 pm

Re: how i can do this with setColor()

Post 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
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: how i can do this with setColor()

Post 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.
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
Post Reply

Who is online

Users browsing this forum: Google [Bot], MrFariator and 71 guests