Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to recreate the waves/water effect from Worms ( see here ) From what I understand its not actually a sprite, its procedurally generated by something like a sin wave.

Has anyone created something like this before? or any idea how I would go about it?

share|improve this question
up vote 14 down vote accepted

Yes, you are right, this 2D water effect can be simulated using math sine function :

wave = sin(phase + t * frequency) * amplitude

enter image description here

  • phase is a constant, put whatever you want.
  • set t to horizontal position of pixel/vertex you are processing : t = x;
  • change amplitude over the time (that will make the waves moving up and down) :

    amplitude = sin(t * wave_speed) * wave_height

  • combine several waves to get a more relastic effect :

    wave_final = wave0 + wave1 + ... .

    For each wave, change some parameters a little bit (eg: phase, frequency,...).

Here is a quick example i made, using only two waves : (require recent browser and WebGL enabled)

NOTE : this is a shader, but doing this using 2D primitives is the same approach .

EDIT : you dont specify any framework or 2d rendering system, but here is how it could be rendered using polygons / triangle strips :

enter image description here

share|improve this answer
Wow, that's an awesome answer, thanks for the very comprehensive answer. Yea I'm using HTML5 Canvas api for rendering. Thanks again for that, extremely helpful!! – Ciarán Nov 22 '12 at 18:29
Right, though the waves in Worms are clearly not merely sines but more complex; very possibly just superpositions of sines. – leftaroundabout Nov 22 '12 at 20:02
@leftaroundabout - Techincally, every wave function is really just a superposition of an infinite number of sines. Practically, this is still true, but more crude approximations may make your life easier. – Fake Name Nov 22 '12 at 20:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.