Jump to content
  • Advertisement
Sign in to follow this  
lodoss118

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

This topic is 3749 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 tbillyforever@hotmail.com, 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
Advertisement
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{
LPDIRECT3DTEXTURE8 lpTexture;
D3DXIMAGE_INFO info;
PALETTEENTRY* lpPalette;
}DXUIMAGE,*LPDXUIMAGE;

typedef struct{
LPDXUIMAGE lpImage;
LPD3DXSPRITE lpSprite;
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;
}DXUSPRITE,*LPDXUSPRITE;

DXUAPI BOOL DXULoadImage(LPDXUIMAGE image,TCHAR* file,DXUCOLOURKEY colourKey = DXUCK_NOCOLOURKEY);

DXUAPI BOOL DXUDrawSprite(LPDXUSPRITE sprite);




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 GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!