Noob Question: setColor/print troubles

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.
czarmurphy
Prole
Posts: 9
Joined: Fri Feb 24, 2012 4:00 am

Noob Question: setColor/print troubles

Post by czarmurphy »

So I'm having this strange problem with setColor() and my print() statements not seeming to take effect after the first set. Take a look at this and hopefully you'll be able to point out my error:

Code: Select all

elseif gameOver then
          love.graphics.setColor(255, 255, 255)
          love.graphics.rectangle('fill', 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
          
          love.graphics.setColorMode('modulate')
          love.graphics.setColor(0, 0, 0)
          love.graphics.print('The End', love.graphics.getWidth()/2 - 150, love.graphics.getHeight()*0.1) 
else
...
The screen turns a blank white, whereas I had additionally wanted text printed on top of that screen. Similarly, I can change the first setColor() arguments, with the changes taking effect. But whatever I put below that rectangle() call is ignored. What is my problem?

Thanks in advance
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Noob Question: setColor/print troubles

Post by tentus »

I don't get a blank white screen (see attached). Are you putting this code inside of love.draw?
Attachments
Code behind love window.
Code behind love window.
screenie.jpg (63.44 KiB) Viewed 5233 times
Kurosuke needs beta testers
czarmurphy
Prole
Posts: 9
Joined: Fri Feb 24, 2012 4:00 am

Re: Noob Question: setColor/print troubles

Post by czarmurphy »

Thanks for the response. Yes, it's in love.draw(). I honestly can't figure out what on earth is going on.
User avatar
hryx
Party member
Posts: 110
Joined: Mon Mar 29, 2010 2:28 am
Location: SF<CA<USA

Re: Noob Question: setColor/print troubles

Post by hryx »

I notice that your snippet lives inside a conditional statement (elseif gameOver then ...). Are you sure that gameOver is evaluating to true? Try just putting the code inside love.draw() without if/elseif/else, as in tentus' screenshot.
User avatar
molul
Party member
Posts: 264
Joined: Sun Feb 05, 2012 6:51 pm
Location: Valencia, Spain
Contact:

Re: Noob Question: setColor/print troubles

Post by molul »

Can we see the full function code?
czarmurphy
Prole
Posts: 9
Joined: Fri Feb 24, 2012 4:00 am

Re: Noob Question: setColor/print troubles

Post by czarmurphy »

Interestingly enough, the code still doesn't do as expected when outside the conditional. I can easily verify that the conditional is being entered, because I can change the color of the first setColor() and see the changes work as expected.

As for the code, I can post love.draw() in main and Player:update() (the only place where gameOver is modified) in Player:

main.lua

Code: Select all

function love.draw()
	
	if menu.run then
          menu:draw()
     
     elseif gameOver then
          --orig_r, orig_g, orig_b, orig_a = love.graphics.getColor( )
     
          love.graphics.setColor(255, 255, 255)
          love.graphics.rectangle('fill', 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
          
          love.graphics.setColorMode('modulate')
          --ending = 'The End'
          love.graphics.setColor(0, 0, 0)
          love.graphics.print('The End', love.graphics.getWidth()/2, love.graphics.getHeight()*0.1) 
          
          --love.graphics.rectangle('fill', 0,0,love.graphics.getWidth(), love.graphics.getHeight())
     else
	
          --Diagnostic Info
          love.graphics.print('Current Position {', 5, 35)
          love.graphics.print(world.eventHandler.currentPos[1], 140, 35)
          love.graphics.print(world.eventHandler.currentPos[2], 180, 35)
          love.graphics.print(' }', 220, 35)

          love.graphics.print('Player Health: ', 5, 5)
          love.graphics.print(world.player.health, 100, 5)
          
          love.graphics.print('Glow Health: ', 5, 20)
          love.graphics.print(world.glow.health, 100, 20)
          
          love.graphics.setColor(255,255,255,255)
          love.graphics.line(0, 0, 0, 5000)
          love.graphics.line(0, 0, 5000, 0)
          love.graphics.line(0, 5000, 5000, 5000)
          love.graphics.line(5000, 0, 5000, 5000)

          fps = love.timer.getFPS()
          love.graphics.print('FPS: ', 5, 50)
          love.graphics.print(fps, 50, 50)
		  
		  love.graphics.print('Pulse: ', 5, 85)
		  if world.player.isPulseActive == false then
			love.graphics.print('false', 65, 85)
		  else
			love.graphics.print('true', 65, 85)
		  end
		  
		  love.graphics.print('Z1: ', 5, 100)
		  love.graphics.print(world.itemsInZones[1], 50, 100)
		  love.graphics.print('Z2: ', 5, 115)
		  love.graphics.print(world.itemsInZones[2], 50, 115)
		  love.graphics.print('Z3: ', 5, 130)
		  love.graphics.print(world.itemsInZones[3], 50, 130)
          
          world:draw()
          
          love.graphics.rectangle('fill', 0,0,love.graphics.getWidth(), love.graphics.getHeight())
     end
		
end
Player.lua (you can probably ignore most of this)

Code: Select all

function Player:update(dt)

	self.health = self.health - 100
     
     if self.health < 1 then
		--invoke loss condition
          --love.graphics.setColor(0, 0, 0, 0)
          love.graphics.setFont(font_end)
          gameOver = true                                -- Here
     end
	--Calculate color
	colorPerc = self.currentPulseCD/self.maxPulseCD
	
	if self.currentPulseCD == 0 then
		color = {1, 1, 1, 1}
	else
		color = {0 + colorPerc, 1, .5 + math.pow(colorPerc,2)/2, 1}
	end
	
	self.color = color
	
	
	--Calculate Pulse CD
	if self.currentPulseCD ~= 0 then
		self.currentPulseCD = self.currentPulseCD - 1
	end
	
	--Calculate radius
	if self.breathDirection == "in" then
	
		if self.radius < self.minRadius then
		
			self.breathDirection = "out"
			
		end
		
		self.radius = self.radius - 750*(1.0/self.health)
		
	end
	
	if self.breathDirection == "out" then
	
		if self.radius > self.maxRadius then
		
			self.breathDirection = "in"
			
		end
		
		self.radius = self.radius + 750*(1.0/self.health)
		
	end
	
	self.pixelEffect:send('position', {self.x, self.y})
	self.pixelEffect:send('size', self.radius)
	self.pixelEffect:send('col', self.color)
	self.particleSys:update(dt, self.glowhp)
	
end
Thank you again for the continued support.


EDIT: So I commented out the entire (original) love.draw() call and replaced it with only the problematic code, and it printed "The End", like I wanted it to. So that definitely means something... Are the other conditional blocks somehow being entered? Or is it something to do with setColor()?
Last edited by czarmurphy on Fri Feb 24, 2012 7:05 pm, edited 1 time in total.
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Noob Question: setColor/print troubles

Post by tentus »

Why do you have massive rectangles being draw at the end of the conditions? Remember, things are draw in the order they are typed, so a rectangle at the end of the else is going to cover up anything that came before it. Hence, the default case in your if statement is gonna be a big blank rectangle.
Kurosuke needs beta testers
czarmurphy
Prole
Posts: 9
Joined: Fri Feb 24, 2012 4:00 am

Re: Noob Question: setColor/print troubles

Post by czarmurphy »

Funny you should mention that. This is a group project, and in my own time, I, wondering the same, commented out that portion of the code. Turns out that it's necessary in that conditional block, or the player is not drawn correctly.

But that shouldn't affect the other conditional, should it?
User avatar
molul
Party member
Posts: 264
Joined: Sun Feb 05, 2012 6:51 pm
Location: Valencia, Spain
Contact:

Re: Noob Question: setColor/print troubles

Post by molul »

I suggest reducing the problem. What happens if you just put this in your love.draw()? (commenting the rest):

Code: Select all

if gameOver then
          --orig_r, orig_g, orig_b, orig_a = love.graphics.getColor( )
     
          love.graphics.setColor(255, 255, 255)
          love.graphics.rectangle('fill', 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
          
          love.graphics.setColorMode('modulate')
          --ending = 'The End'
          love.graphics.setColor(0, 0, 0)
          love.graphics.print('The End', love.graphics.getWidth()/2, love.graphics.getHeight()*0.1) 
          
          --love.graphics.rectangle('fill', 0,0,love.graphics.getWidth(), love.graphics.getHeight())
     end
czarmurphy
Prole
Posts: 9
Joined: Fri Feb 24, 2012 4:00 am

Re: Noob Question: setColor/print troubles

Post by czarmurphy »

One of my team members (who had been working on similar code) found and fixed the problem. BlendMode, which had previously been altered, needed to be set to 'alpha'. Thanks for all the help.
Post Reply

Who is online

Users browsing this forum: Amazon [Bot], Google [Bot] and 5 guests