goku
goku game engine_en
goku game engine_en
  • Chapter 1: Introduction to SDL2, Rust, and goku
  • Chapter2: The Base Structure: SpriteSheet
  • Chapter 3: Animated Textures
  • Chapter 4: Handling Textures: TextureManager
  • Chapter 5: Bringing Textures to Life: GameObject
  • Chapter 6: The Foundation: Tile System
  • Chapter 7: Moving the View: Camera
  • Chapter 8: Particle System
  • Chapter 9: The User Interface Layer
  • Chapter 10: The Button Element
  • Chapter 11: The Text Box Element
  • Chapter 12: The Checkbox Element
  • Chapter 13: The Slider Element
  • Chapter 14: The Audio System
  • Chapter 15: The AI System
  • Chapter 16: The Window System
  • Chapter 17: User Input Handling
  • Chapter 18: Rendering a Parallax Background
  • Chapter 19: Timing and Frame Rate Management
  • Chapter 20: Conclusion
Powered by GitBook
On this page

Chapter 18: Rendering a Parallax Background

In this chapter, we'll go through the implementation of a parallax background, which is a technique used in 2D games to give a sense of depth.

The ParallaxLayer struct represents a single layer in our parallax background. Each layer has its own texture and speed, creating a sense of depth by moving slower the further it is from the viewer. The ParallaxBackground struct manages multiple layers, rendering and updating each layer.

The render method of a ParallaxLayer handles drawing the layer's texture to the screen, taking into account the layer's offset and the position of the camera. The update method adjusts the layer's offset based on its speed and the elapsed time.

The ParallaxBackground's render and update methods simply call the corresponding methods on each of its layers.

PreviousChapter 17: User Input HandlingNextChapter 19: Timing and Frame Rate Management

Last updated 1 year ago