Advertisement Jump to content
Sign in to follow this  

How do to do the 2d wave effect on sprites?

This topic is 3842 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi what i am trying to do is get the same effect in 2d games like super metroid where the background would display a 2d wave effect, i was wondering if anyone could help to implement this in my engine if so my msn is, i would appreciate it anyone could look at my source and show me hwo to implement that effect?

Share this post

Link to post
Share on other sites
I'm also interested in learning how to perform this.
The only (hackish) way I can think of is doing an animation through a texture but that would be a pain.

I'm doing it in XNA/C# which has shader support.

I'm sure some sort of use of particles could also do this. But I cant put my head around that.

[Edited by - dzeligman on July 15, 2008 11:03:34 AM]

Share this post

Link to post
Share on other sites
If you are using shaders, you can add a small sin/cos term to the texture coordinates.

I'm a bit rusty on GLSL, but this should work:

uniform sampler2D texture;

uniform float amplitude;
uniform float frequency;
uniform float phase;

void main()
float offset = amplitude * cos(frequency * gl_TexCoord[0].t + phase);
vec2 texCoord = vec2(gl_TexCoord[0].s + offset, gl_TexCoord[0].t);

gl_FragColor = texture2D(texture, texCoord);

(HLSL should be quite similar as well)

What this does is that it adds a displacement to the texture coordinate gl_TexCoord[0].s based on gl_TexCoord[0].t. Try playing with the amplitude and frequency to change how the waves look and to animate the waves, update the phase variable each frame.

More reading

Share this post

Link to post
Share on other sites
hmm i am using directx and have structure called DXUIMAGE and DXUSPRITE

typedef struct{

typedef struct{
D3DXVECTOR2 scale;
D3DXVECTOR2 rotateCenter;
D3DXVECTOR2 translate;
D3DCOLOR colour;
double rotation;
RECT srcRect;
double x,y;
double tw,th; // Transformed Width and Height
double isMirrorLeft,isMirrorTop;



how would i apply the maths to above structures to get the effect me confused.

Share this post

Link to post
Share on other sites
It depends on if the helper library you seem to be using have any support for custom shaders. Try looking though the library and see if anything pops up. Otherwise you probably have to work directly with DirectX, in which case try searching for "directx effect file" on google and you'll find some ok resources on how to load and use shaders in a farily simple way.

Share this post

Link to post
Share on other sites
as i have already a method to scale sprites and translate them isn't there a way to do maths using scale techniques?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!