Game Loop Prompts
AI prompts for game loop from the LearnWithHasan AI Coding Building Blocks (Game Dev).
Create a Basic Game Loop
Start here when building any new game From the Game Loop AI Coding Building Block.
Create a basic game loop for my [language/framework, e.g., Python/Pygame, JavaScript/Canvas, C++/SDL]. I need the loop to: 1. Track time between frames (delta time) 2. Process player input 3. Update game state (positions, physics, AI) 4. Render everything to screen 5. Cap frame rate to [target FPS, e.g., 60] Include: - A simple moving object that uses delta time for consistent speed - Basic structure I can expand later - Comments explaining each section I'm learning game development, so explain why we need delta time and how it makes the game run the same on fast and slow computers.
Add Delta Time to Existing Game
For fixing games that run too fast or slow on different computers From the Game Loop AI Coding Building Block.
My game currently moves objects without delta time and runs at different speeds on different computers. Current movement code: [paste your movement code, e.g., "player.x += 5"] Help me: 1. Calculate delta time (time since last frame) 2. Convert my movement to be time-based instead of frame-based 3. Ensure physics and animations stay consistent at any frame rate My game uses: [language/framework] Current target FPS: [e.g., 60] Explain what delta time is and show before/after examples so I understand the change.
Implement Fixed Timestep for Physics
For games with precise physics requirements From the Game Loop AI Coding Building Block.
I need to implement a fixed timestep game loop for reliable physics simulation. My game has: [describe physics, e.g., "platformer with jumping and gravity" or "ball physics with collisions"] Create a game loop that: 1. Uses a fixed timestep for physics updates (e.g., 1/60th of a second) 2. Accumulates time and runs multiple physics steps if needed 3. Interpolates rendering between physics states for smooth visuals 4. Handles the "spiral of death" (when physics can't keep up) My framework: [language/framework] I'm learning about fixed vs variable timestep. Explain why physics needs fixed timestep but rendering can be variable, and what problems this solves.
Browser Game Loop with requestAnimationFrame
For HTML5 Canvas or WebGL games From the Game Loop AI Coding Building Block.
Help me create a proper game loop for a browser-based game using requestAnimationFrame. I want to build: [describe your game, e.g., "a simple 2D platformer" or "a physics sandbox"] The loop should: 1. Use requestAnimationFrame for smooth rendering 2. Calculate delta time correctly (handling tab switching) 3. Cap maximum delta time to prevent physics explosions 4. Include a simple game state with update and render separation Also show me: - How to pause/resume the loop - How to handle the tab becoming inactive - Basic performance monitoring (FPS counter) I'm new to browser game development, so explain the differences from traditional game loops and why requestAnimationFrame is preferred over setInterval.