简体   繁体   中英

Libgdx - setting Sprite color

Is it possible to .setColor(x,x,x,1) for a border of a circle like this:

在此处输入图片说明

else I have to use 2 sprites, and I already have 500 sprites referenced. Do not want to use a 1000.

Just simply use two different textures, one with a filled-in circle and one with only a stroke. Set the texture of whichever sprite needs a stroked or a filled circle using the setTexture method in the libGDX Sprite class.

This is still efficient since the textures only need to be loaded once and by setting the texture of a sprite it only keeps a pointer in memory not the whole texture.

To do it in one pass with a custom shader, encode your source sprite in a certain way. Like this:

在此处输入图片说明

Now you can blend between white and your border color using the R channel as the interpolation factor. You can copy the vertex shader from the SpriteBatch source code and modify the fragment shader main function to look like this:

vec4 texColor = texture2D(u_texture, v_texCoords);
gl_FragColor = vec4(mix(vec3(1.0), v_color.rgb, texColor.rrr), v_color.a * texColor.a);

I would go with the TextureRegion idea above and when you've finished your game, IF your having performance issues THEN and only then would i really worry about this, but im somewhat scared of shaders.

Most people never finish their games because they get caught up in the details way before they really need to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM