2D Game Development 2D Game Programming Concepts 2 — Questions and Answers
Question 1: What is the purpose of a 'finite state machine' (FSM) in 2D game AI?
- Modeling entity behavior as a set of states with defined transitions between them (Correct answer)
- Limiting the number of active entities
- A performance optimization for physics
- A data compression algorithm
Correct answer: Modeling entity behavior as a set of states with defined transitions between them
An FSM organizes AI behavior into discrete states (patrol, chase, attack) and defines the conditions that cause the AI to switch between them.
Question 2: What is 'lerp' (linear interpolation) commonly used for in 2D games?
- Smoothly transitioning a value between a start and end point over time (Correct answer)
- Loading level data progressively
- Calculating the shortest path between two nodes
- Randomly selecting a value in a range
Correct answer: Smoothly transitioning a value between a start and end point over time
Lerp calculates intermediate values between two points based on a 0–1 parameter, used for smooth camera follow, UI transitions, and object movement.
Question 3: What is 'input buffering' in 2D action games?
- Recording a player input slightly before the action is valid so it executes at the earliest opportunity (Correct answer)
- Storing all inputs for replay
- Smoothing analog stick input
- Debouncing keyboard input
Correct answer: Recording a player input slightly before the action is valid so it executes at the earliest opportunity
Input buffering stores a recent input command for a brief window so it triggers as soon as the relevant condition is met, making controls feel responsive.
Question 4: What is 'scene management' in a 2D game engine?
- Loading, unloading, and transitioning between different game screens and levels (Correct answer)
- Managing physics scene layers
- Organizing assets in the project folder
- Controlling the rendering pipeline
Correct answer: Loading, unloading, and transitioning between different game screens and levels
Scene management handles loading level data, transitioning to new scenes (menus, levels, cutscenes), and cleaning up previous scene resources.
Question 5: What is 'data serialization' used for in 2D game development?
- Converting game state to a storable format (JSON, binary) for saving and loading (Correct answer)
- Sorting game objects by ID
- Transmitting audio data between systems
- Compiling game scripts
Correct answer: Converting game state to a storable format (JSON, binary) for saving and loading
Serialization transforms runtime objects (player stats, level state) into a storable byte format that can be written to disk and deserialized to restore the game state.
Question 6: What is 'coroutine' or 'async function' commonly used for in 2D game scripting?
- Pausing execution over multiple frames to spread out work or create timed sequences (Correct answer)
- Running multiple scripts simultaneously on different threads
- Scheduling physics updates
- Preloading assets asynchronously only
Correct answer: Pausing execution over multiple frames to spread out work or create timed sequences
Coroutines yield execution back to the game loop for a frame (or a set time), enabling sequences like fade-outs, countdowns, and wave spawning without blocking.
What is the purpose of a 'finite state machine' (FSM) in 2D game AI?