Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (799)
Games in Android Showcase (237)
games submitted by our members
Games in WIP (865)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [LibGDX] Tint part of sprite  (Read 4341 times)
0 Members and 1 Guest are viewing this topic.
Offline Victor7

Senior Newbie


Exp: 1 year



« Posted 2014-08-04 15:25:16 »

I'm making a strategy game. In the game, all players have the same units, differentiated by army color.
The problem is that I don't want to make the same texture ten times with ten different colors; instead of that, I want to use ONE texture and tint the sprite by code.

I know that I can change the spriteBatch color or use sprite.setColor. However, that change the color of the whole image, and I don't want that. The idea is to tint only a part of the sprite, like its t-shirt.
I've read about shaders, but I don't know if they can provide a solution to my problem. Also, I have no idea of shaders xD

I've thought that a solution can be split my texture in two textures. One texture will have the immutable colors of my texture, and the other one will be in grayscale, and tinted using sprite.setColor. However I think this is not the best solution.

Ideas are welcome  Smiley Thanks in advance.
Offline trollwarrior1
« Reply #1 - Posted 2014-08-04 15:33:10 »

Make a few images for different parts of the sprite (Sleeves and body in T-shirt case)  and draw 2 sprites with different colors.
Offline atombrot
« Reply #2 - Posted 2014-08-04 16:01:45 »



I've thought that a solution can be split my texture in two textures. One texture will have the immutable colors of my texture, and the other one will be in grayscale, and tinted using sprite.setColor. However I think this is not the best solution.

Ideas are welcome  Smiley Thanks in advance.

I would do exactly that. It is simple and it works. Why bother looking for a more complicated solution.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Victor7

Senior Newbie


Exp: 1 year



« Reply #3 - Posted 2014-08-04 16:44:28 »

Quote
I would do exactly that. It is simple and it works. Why bother looking for a more complicated solution.

The solution is not bad I think, however if there's another solution with better perfomance (and not very difficult to implement) I would use it.

If I can't find more options, I will simply do that. But I want to know what other things can I do.

Offline thedanisaur

JGO Knight


Medals: 59



« Reply #4 - Posted 2014-08-04 17:49:13 »

Another way is to draw directly on/over your sprite, only certain pixels. The problem with this is that it gets pretty involved.

Every village needs an idiot Cool
Offline pitbuller
« Reply #5 - Posted 2014-08-04 18:37:23 »

This is really easy problem if you can provide mask for a shader. Mask only need one bit so you could encode that to certain color. Coder pink aka red255 green0 blue 255 could be used. Then green channel could be intensity of tinted color.

1  
2  
if (color.r == 1.0 && color.g == 1.0)
  color.rgb = v_color * color.g;
Offline ags1

JGO Kernel


Medals: 367
Projects: 7


Make code not war!


« Reply #6 - Posted 2014-08-04 20:11:53 »

+1 for shader. If you are not using the alpha channel for anything real, you can use that to flag the shader coloring, and even blend with the sprite rgb (so the color added by the shader is modulated and is not one flat color).

Offline Victor7

Senior Newbie


Exp: 1 year



« Reply #7 - Posted 2014-08-05 09:42:53 »

The problem is that I know NOTHING about shaders xD
I think they can be the most efficient solution but I don't know how to use them. I'm reading some tutorials, like this, http://www.alcove-games.com/opengl-es-2-tutorials/lightmap-shader-fire-effect-glsl/ and somethings here in jgo, but I don't understand the shader code u.u

If you know a very very basic tutorial or you can post some basic code I would appreciate it.
Thanks for the recommendations.  Smiley

EDIT: another problem is that using that method I wouldn't be able to manage shadows. If I substitute (255,0,255) by another color, how I get shadows? Then using an alpha trick would be a solution, but looks like I will have to do it completely manual...

Offline pitbuller
« Reply #8 - Posted 2014-08-05 17:03:29 »

EDIT: another problem is that using that method I wouldn't be able to manage shadows. If I substitute (255,0,255) by another color, how I get shadows? Then using an alpha trick would be a solution, but looks like I will have to do it completely manual...

Like in the code I posted you use green channel as intesity.
Pages: [1]
  ignore  |  Print  
 
 

 
Riven (187 views)
2019-09-04 15:33:17

hadezbladez (4874 views)
2018-11-16 13:46:03

hadezbladez (1785 views)
2018-11-16 13:41:33

hadezbladez (5147 views)
2018-11-16 13:35:35

hadezbladez (1016 views)
2018-11-16 13:32:03

EgonOlsen (4367 views)
2018-06-10 19:43:48

EgonOlsen (5216 views)
2018-06-10 19:43:44

EgonOlsen (2946 views)
2018-06-10 19:43:20

DesertCoockie (3867 views)
2018-05-13 18:23:11

nelsongames (4293 views)
2018-04-24 18:15:36
Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!