Image Colour Workaround?

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
Neon
Prole
Posts: 16
Joined: Sun Apr 01, 2012 3:46 pm

Image Colour Workaround?

Post by Neon »

When I set the colour of text, it changes the colour like it should. However, I can set the colour for my image, because it uses multiple colours (as most images do). How do I make it so when I use a image, it stay the colour it is, and is not affected by the current colour?

I tried:

Code: Select all

love.graphics.setColourMode("replace")
but that screwed up all the other colours, and just didn't work.
User avatar
Larsii30
Party member
Posts: 267
Joined: Sun Sep 11, 2011 9:36 am
Location: Germany

Re: Image Colour Workaround?

Post by Larsii30 »

Could you post the code ?
Whould be easier.

You could do it like this:

Code: Select all

love.graphics.setColorMode("replace") -- images will not be affected by current color

function love.draw()

    love.graphics.setColorMode("modulate") -- image WIILL be affected

    love.graphics.setColor(0,255,0)
    love.graphics.print("hello, i'm Green!", 10,10)
    love.graphics.setColorMode("replace")   --not sure if that is needed

  love.graphics.print("not Green, yeaaah!", 30 , 30)

end
edit (or without push pop :D code should work)
Last edited by Larsii30 on Sun Apr 29, 2012 9:22 pm, edited 5 times in total.
Zeliarden
Party member
Posts: 139
Joined: Tue Feb 28, 2012 4:40 pm

Re: Image Colour Workaround?

Post by Zeliarden »

Code: Select all

love.graphics.setColor(255, 255, 255)
just call it whenever you need to change color. Set it to (255, 255, 255) before you images for orginal color
Neon
Prole
Posts: 16
Joined: Sun Apr 01, 2012 3:46 pm

Re: Image Colour Workaround?

Post by Neon »

Larsii, I somewhat understand what you mean. Is there a easier way? I assume I could use your system, but a easier way would work much better.

Here is the function to draw all the objects in my lib.

Code: Select all

function Lib.draw() -- Draws all the objects.
    for k, obj in pairs(Objects) do
		if obj.objtype == "Label" then
			love.graphics.setColor(obj.red, obj.green, obj.blue)
			love.graphics.setFont(love.graphics.newFont(obj.fontsize))
			love.graphics.print(obj.words, obj.xpos, obj.ypos)
		elseif obj.objtype == "Button" then
			love.graphics.setColor(obj.red, obj.green, obj.blue)
			love.graphics.rectangle(obj.status, obj.xpos, obj.ypos, obj.height, obj.width)
		elseif obj.objtype == "Image" then
			love.graphics.draw(obj.pic, obj.x, obj.y)
		end
	end
end
Say a button is drawn before a image. The colour is set to the colour of the button. Then when you draw a image, it uses that colour. That's what I'm trying to avoid.
Neon
Prole
Posts: 16
Joined: Sun Apr 01, 2012 3:46 pm

Re: Image Colour Workaround?

Post by Neon »

Nevermind, Zeliarden's worked. Thanks.
User avatar
Larsii30
Party member
Posts: 267
Joined: Sun Sep 11, 2011 9:36 am
Location: Germany

Re: Image Colour Workaround?

Post by Larsii30 »

actually you're right . Didn't know that.
Then I could use it like this too :)
Thanks
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 89 guests