So in my project, I want to make it so that when you hit an enemy, they flash white for a brief moment, maybe making it flash in and out around 5-8 times, but I don’t want to make extra frames for it, and IDK how to make shaders, but the best way to do it is probably to use shaders anyway, how do I make it so that the enemies flash after taking damage? I really need help with this because I am a noob at shaders.
code: PlayCanvas | HTML5 Game Engine
Map: PlayCanvas | HTML5 Game Engine
I am thinking of something like what Inbound Shovel talks about here: https://www.youtube.com/watch?v=8wpfCTKQ8jU
I will also be adding a hurt animation to the Alphadels to go along with the flashing, I think the animation, like the flashing, should only last around a quarter of a second.
I have a shader(I think), but how do I implement it?
Well, I kinda see how to implement it, but do I need a Vertex shader just for a spritesheet? Or do I just need a fragment shader? Everything on the Docs site uses it only for 3D models and Materials, but this doesn’t use either.
I’m guessing all I need from the Custom shaders doc page is:
var app = this.app;
var gd = app.graphicsDevice;
var fragmentShader = "precision " + gd.precision + " float;\n";
fragmentShader = fragmentShader + this.fs.resource;
// A shader definition used to create a new shader.
var shaderDefinition = {
attributes: {
aPosition: pc.SEMANTIC_POSITION,
aUv0: pc.SEMANTIC_TEXCOORD0
},
fshader: fragmentShader
};
// Create the shader from the definition
this.shader = new pc.Shader(gd, shaderDefinition);
But I am so confused about what
aPosition: pc.SEMANTIC_POSITION,
aUv0: pc.SEMANTIC_TEXCOORD0
They are in the definition of the shader. And after I make the shader, how would I apply the shader to the sprite?
BTW: the Fragment Shader Code I have is:
precision mediump float;
uniform sampler2D u_texture;
varying vec2 v_texCoord;
void main() {
vec4 color = texture2D(u_texture, v_texCoord);
if (color.a > 0.0) {
gl_FragColor = vec4(1.0, 1.0, 1.0, color.a); // White with original alpha
} else {
gl_FragColor = color; // Keep original color if transparent
}
}