in Engine

Castle Game Engine: Water effect ready to use in 2D games, like a platformer demo

From Castle Game Engine: link to original post

2D water in a platformer demo 2D water in a platformer demo

Project cge-2d-water-effect by Trung Le (Kagamma) shows how to do a beautiful water for 2D games. The water is represented as a volume that you can easily move and scale around. It supports reflection and refraction.

Under the movies, we list detailed usage instructions, so read on 🙂

Technically, it is expressed as an X3D scene with a geometry and a special shader, that you should load into a special TCastleScene descendant: TCastleSceneScreenBuffer. The viewport containing this must also be of special class, TCastleViewportScreenBuffer.

The setup can be tested with any 2D game designed in CGE viewport. E.g. you can place water volume in our examples/platformer/ game demo.

Detailed usage instructions:

  1. Get cge-2d-water-effect code.

  2. Point your project to cge-2d-water-effect sources. E.g. add this to CastleEngineManifest.xml:

      <compiler_options>
        <search_paths>
          <path value="code/" />
          <path value="../../../cge-2d-water-effect/src/" />
        </search_paths>
      </compiler_options>
    
  3. Include custom components in your project.

    1. Add to CastleEngineManifest.xml the line editor_units="CastleSceneScreenBuffer, CastleViewportScreenBuffer". See CastleEngineManifest.xml docs for examples.

    2. Open your project in CGE editor and use “Project -> Restart Editor (With Custom Components)”

    3. Be sure to also add CastleSceneScreenBuffer, CastleViewportScreenBuffer to some uses clause, to register components at runtime.

  4. Copy the cge-2d-water-effect/data into your project data, e.g. into my-project/data/2d-water/.

  5. Use TCastleViewportScreenBuffer where you would normally use TCastleViewport.

  6. Add to viewport instance of TCastleViewportScreenBuffer. Load there castle-data:/water2d/2d_water_plane.x3dv. Move it, scale, duplicate as necessary to set up your water volume.