2D Game Development 2D Game Optimization and Performance 2 — Questions and Answers
Question 1: What is the benefit of using a fixed-timestep update loop in a 2D game?
- It locks the rendering frame rate to 60 FPS regardless of GPU load
- It makes physics and game logic deterministic and independent of rendering frame rate (Correct answer)
- It reduces memory allocations by reusing update buffers each frame
- It batches input events into a single call per second
Correct answer: It makes physics and game logic deterministic and independent of rendering frame rate
A fixed timestep ensures physics and game logic always advance by the same delta time, making simulations reproducible and preventing instability caused by variable frame times.
Question 2: Which approach best reduces CPU overhead when updating hundreds of similar game entities each frame?
- Storing each entity as a separate class instance with virtual method dispatch
- Using a Data-Oriented Design (DOD) approach with structs-of-arrays for cache-friendly iteration (Correct answer)
- Assigning each entity its own thread for parallel updates
- Offloading all entity logic to a scripting language interpreter
Correct answer: Using a Data-Oriented Design (DOD) approach with structs-of-arrays for cache-friendly iteration
Structs-of-arrays layout keeps the same field type for all entities contiguous in memory, maximizing CPU cache utilization and SIMD vectorization opportunities during mass updates.
Question 3: In 2D games, 'batching' render calls means:
- Grouping level geometry into pre-built static meshes
- Combining multiple sprite draw operations into a single GPU draw call when they share a texture and shader (Correct answer)
- Compressing multiple animation frames into one keyframe
- Sending input events in bulk to reduce OS call frequency
Correct answer: Combining multiple sprite draw operations into a single GPU draw call when they share a texture and shader
Batching merges sprites that share the same texture and material into one draw call, dramatically reducing CPU-to-GPU command overhead.
Question 4: What problem does mipmapping solve in 2D games that use camera zoom-out?
- It prevents texture bleeding at sprite sheet borders during sampling
- It reduces aliasing and texture cache misses when sprites are rendered smaller than their native resolution (Correct answer)
- It compresses textures to reduce VRAM usage at all zoom levels
- It generates collision shapes automatically from texture data
Correct answer: It reduces aliasing and texture cache misses when sprites are rendered smaller than their native resolution
Mipmaps are pre-downscaled versions of a texture; the GPU samples the appropriately sized mip level when a sprite appears small on screen, reducing aliasing and improving texture cache efficiency.
Question 5: Which memory layout concern is most relevant to 2D particle system performance?
- Storing particle colors as 32-bit floats to increase precision
- Keeping particle data in contiguous arrays (SOA) to enable SIMD processing and reduce cache misses (Correct answer)
- Allocating each particle on the heap individually for easy lifetime management
- Using linked lists so particles can be inserted and removed in O(1) time
Correct answer: Keeping particle data in contiguous arrays (SOA) to enable SIMD processing and reduce cache misses
Struct-of-Arrays layout for particle positions, velocities, and lifetimes enables vectorized (SIMD) updates and keeps accessed data contiguous in the CPU cache.
Question 6: What is the purpose of 'level-of-detail' (LOD) for sprites in a 2D game with zoom?
- Switching to lower-resolution sprite variants when they appear small on screen to save texture bandwidth (Correct answer)
- Adding more animation frames to sprites that are close to the camera
- Replacing physics shapes with simpler versions as distance increases
- Enabling HDR rendering only for sprites in the foreground layer
Correct answer: Switching to lower-resolution sprite variants when they appear small on screen to save texture bandwidth
Sprite LOD swaps in smaller, lower-resolution versions when a sprite is rendered at a small size, reducing texture memory bandwidth and maintaining visual quality at the appropriate detail level.
Question 7: In a 2D tile-based game, why is it common to pre-bake static tilemaps into a single large mesh or render texture?
- It allows the tilemap to be edited at runtime without re-uploading to the GPU
- It eliminates per-tile draw calls, reducing CPU overhead to a single draw call for the entire static layer (Correct answer)
- It enables per-tile lighting calculations to be performed in the fragment shader
- It stores collision metadata directly in vertex attributes for faster physics
Correct answer: It eliminates per-tile draw calls, reducing CPU overhead to a single draw call for the entire static layer
Baking a static tilemap into one mesh or texture means the entire layer is drawn in a single GPU command, removing the overhead of issuing thousands of individual sprite draw calls each frame.
What is the benefit of using a fixed-timestep update loop in a 2D game?