2D Game Development 2D Game Optimization and Performance 1 — Questions and Answers
Question 1: What is the primary purpose of a texture atlas (sprite sheet) in 2D game optimization?
- To increase the color depth of sprites
- To reduce draw calls by batching multiple textures into a single GPU bind (Correct answer)
- To enable procedural texture generation at runtime
- To store collision data alongside sprite pixels
Correct answer: To reduce draw calls by batching multiple textures into a single GPU bind
A texture atlas combines multiple sprites into one texture, allowing the GPU to render many sprites in fewer draw calls, which significantly reduces CPU-GPU communication overhead.
Question 2: Which rendering technique minimizes overdraw in a 2D game scene?
- Drawing sprites in back-to-front (painter's algorithm) order only
- Drawing opaque sprites front-to-back so the depth buffer rejects hidden pixels early (Correct answer)
- Using additive blending for all sprites
- Rendering all sprites at half resolution then upscaling
Correct answer: Drawing opaque sprites front-to-back so the depth buffer rejects hidden pixels early
Drawing opaque objects front-to-back lets the depth test discard pixels that would be hidden, reducing the number of fragments the GPU needs to shade.
Question 3: What does 'object pooling' solve in 2D game performance?
- It reduces texture memory usage by sharing sprites between objects
- It avoids frequent heap allocations and garbage collection spikes by reusing objects (Correct answer)
- It groups game objects into spatial pools for faster physics
- It batches audio sources to reduce CPU audio thread load
Correct answer: It avoids frequent heap allocations and garbage collection spikes by reusing objects
Object pooling pre-allocates a fixed number of objects and recycles them, preventing the garbage collector from running frequently and causing frame rate hitches.
Question 4: In a 2D game, a 'dirty flag' pattern is most useful for:
- Marking sprites that need re-rendering after a physics update
- Avoiding redundant transform recalculations on objects that haven't moved (Correct answer)
- Flagging corrupted save data for recovery
- Tracking which tiles have been visited by the player
Correct answer: Avoiding redundant transform recalculations on objects that haven't moved
A dirty flag marks a cached value as stale only when the underlying data changes, so transforms are only recalculated when an object has actually moved or rotated.
Question 5: What is the main advantage of using a quadtree in a 2D game?
- It stores tile UV coordinates for fast texture lookup
- It partitions space to speed up spatial queries like collision broad-phase detection (Correct answer)
- It compresses sprite animation data for faster streaming
- It balances load across multiple CPU cores
Correct answer: It partitions space to speed up spatial queries like collision broad-phase detection
A quadtree recursively subdivides 2D space, allowing the broad-phase collision system to quickly eliminate pairs of objects that are too far apart to collide.
Question 6: Which metric most directly measures whether a 2D game is GPU-bound vs. CPU-bound?
- Total RAM usage reported by the OS
- GPU frame time vs. CPU frame time per frame in a profiler (Correct answer)
- Number of active game objects in the scene
- Texture resolution of the largest sprite in memory
Correct answer: GPU frame time vs. CPU frame time per frame in a profiler
Comparing GPU frame time to CPU frame time in a GPU profiler reveals which processor is the bottleneck; the one with the higher time is the limiting factor.
Question 7: What is 'frustum culling' adapted to in a 2D game context?
- Removing vertices outside the camera frustum before rasterization
- Skipping rendering of sprites whose bounding rectangles lie entirely outside the camera viewport (Correct answer)
- Cutting audio sources that are outside the audible range of the player
- Disabling physics on objects beyond a certain distance from the origin
Correct answer: Skipping rendering of sprites whose bounding rectangles lie entirely outside the camera viewport
In 2D, culling checks whether a sprite's bounding rectangle intersects the camera's viewport rectangle; sprites entirely outside are not submitted for rendering.
What is the primary purpose of a texture atlas (sprite sheet) in 2D game optimization?