![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Ron0Studios |
Hello There,
I have been working on a game project for quite a while now. There is a character that can dash (fast) in the game and I want to provide some player feedback upon dashing. So I followed (this) tutorial on creating a ghost effect when somebody dashes. So I modified the tutorial so you can have the “ghost” have a solid colour that tweens to alpha over time. Previously I have been using shaders to implement a solid colour. Here is the code:
shader_type canvas_item;
uniform vec4 colour : hint_color;
uniform bool active;
void fragment() {
if(active == true) {
vec4 curr_color = texture(TEXTURE,UV); // Get current color of pixel
if (curr_color.a == 1.0f){
COLOR.rgb = colour.rgb;//vec3(0.238, 0.118, 0.418);
}else{
COLOR = curr_color;
}
}
else{
COLOR = texture(TEXTURE,UV);
}
}
This did the job well for a long time, but I noticed a performance issue. Upon the first dash, the player would get a very large lag spike, but afterwards, there was no lag from dashing at all. At first, I thought this was due to loading the resources, so I tried using preload() functions or instancing at different points, but nothing seemed to work. Later on, I found out that it was due to the fact that shaders were lazily compiled in-game, so when an object is instanced for the first time, there would be massive game lag. Are there any solutions to having a sprite with a solid colour fill in GDscript without using any materials or shaders?
Thanks,
PS. I don’t think modulate or self modulate works. It doesn’t give a solid fill colour.
Maybe I’m missing the point, but why not just provide a solid color version of the sprite for use in the dash feature?
jgodfrey | 2020-05-29 16:43