Coloring a spriteBatch sprite

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
KayleMaster
Party member
Posts: 234
Joined: Mon Aug 29, 2016 8:51 am

Coloring a spriteBatch sprite

Post by KayleMaster »

I have soldiers, and to distinguish enemy from friendly, I decided to color them respectively blue and red.
This is simple if it's a sprite via draw.setColor but how would I go about a spriteBatch? (one batch can have both colored units)
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Coloring a spriteBatch sprite

Post by bartbes »

Like love.graphics.setColor does without SpriteBatches, SpriteBatch:setColor affects the colour of the sprites added after the call.
User avatar
Tjakka5
Party member
Posts: 243
Joined: Thu Dec 26, 2013 12:17 pm

Re: Coloring a spriteBatch sprite

Post by Tjakka5 »

Doing SpriteBatch:setColor will alter the color of all the next sprites you set/add in the batch; similar to how love.graphics.setColor works.
Documentation here:
https://love2d.org/wiki/SpriteBatch:setColor
KayleMaster
Party member
Posts: 234
Joined: Mon Aug 29, 2016 8:51 am

Re: Coloring a spriteBatch sprite

Post by KayleMaster »

Damn! Thanks, I didn't see that!
I knew there was a way..

EDIT: Is it possible to achieve something like this code-wise ?
Image
User avatar
Tjakka5
Party member
Posts: 243
Joined: Thu Dec 26, 2013 12:17 pm

Re: Coloring a spriteBatch sprite

Post by Tjakka5 »

Sure!

First, the sprite you want to edit needs to be white so the color will apply correctly.
If you want to color a sprite partially, you have to separate it into multiple.

You can edit the color with just RGB(A) values. But if you really want HSV you can look into converting it.
https://gist.github.com/raingloom/3cb61 ... caa326a25a
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 56 guests