-
Notifications
You must be signed in to change notification settings - Fork 0
Tutorial Pong
Select your language / Choisissez votre langue / Wählen Sie Ihre Sprache:
English | Français | Deutsch | Italiano | Español | Português | Slovenščina | Українська | Русский
In this tutorial, you'll create a classic Pong game - one of the first video games ever made! Pong is a two-player game where each player controls a paddle and tries to hit the ball past their opponent's paddle to score points.
What you'll learn:
- Creating sprites for paddles, ball, and walls
- Handling keyboard input for two players
- Making objects bounce off each other
- Tracking and displaying scores for both players
- Using global variables
Difficulty: Beginner Preset: Beginner Preset
Before we start, let's understand what we need:
| Element | Purpose |
|---|---|
| Ball | Bounces between players |
| Left Paddle | Player 1 controls with W/S keys |
| Right Paddle | Player 2 controls with Up/Down arrows |
| Walls | Top and bottom boundaries |
| Goals | Invisible areas behind each paddle to detect scoring |
| Score Display | Shows both players' scores |
- In the Resource Tree, right-click on Sprites and select Create Sprite
- Name it
spr_ball - Click Edit Sprite to open the sprite editor
- Draw a small white circle (about 16x16 pixels)
- Click OK to save
We'll create two paddles - one for each player:
Left Paddle (Player 1):
- Create a new sprite named
spr_paddle_left - Draw a tall, thin rectangle curved like a parenthesis ")" - blue color recommended
- Size: approximately 16x64 pixels
Right Paddle (Player 2):
- Create a new sprite named
spr_paddle_right - Draw a tall, thin rectangle curved like a parenthesis "(" - red color recommended
- Size: approximately 16x64 pixels
- Create a new sprite named
spr_wall - Draw a solid rectangle (gray or white)
- Size: 32x32 pixels (we'll stretch it in the room)
- Create a new sprite named
spr_goal - Make it 32x32 pixels
- Leave it transparent or make it a solid color (it will be invisible in the game)
![]()
The wall object creates boundaries at the top and bottom of the play area.
- Right-click on Objects and select Create Object
- Name it
obj_wall - Set the sprite to
spr_wall - Check the "Solid" checkbox - this is important for bouncing!
- No events needed - the wall just sits there

- Create a new object named
obj_paddle_left - Set the sprite to
spr_paddle_left - Check the "Solid" checkbox
Add Keyboard Events for Movement:
Event: Keyboard Press W
- Add Event → Keyboard → Press W
- Add Action: Move → Set Vertical Speed
- Set vertical speed to
-8(moves up)
Event: Key Release W
- Add Event → Keyboard → Release W
- Add Action: Move → Set Vertical Speed
- Set vertical speed to
0(stops moving)
Event: Keyboard Press S
- Add Event → Keyboard → Press S
- Add Action: Move → Set Vertical Speed
- Set vertical speed to
8(moves down)
Event: Key Release S
- Add Event → Keyboard → Release S
- Add Action: Move → Set Vertical Speed
- Set vertical speed to
0(stops moving)
Event: Collision with obj_wall
- Add Event → Collision → obj_wall
- Add Action: Move → Bounce (no configuration needed — it always bounces off solid objects)
- Create a new object named
obj_paddle_right - Set the sprite to
spr_paddle_right - Check the "Solid" checkbox
Add Keyboard Events for Movement:
Event: Keyboard Press Up Arrow
- Add Event → Keyboard → Press Up
- Add Action: Move → Set Vertical Speed
- Set vertical speed to
-8
Event: Key Release Up Arrow
- Add Event → Keyboard → Release Up
- Add Action: Move → Set Vertical Speed
- Set vertical speed to
0
Event: Keyboard Press Down Arrow
- Add Event → Keyboard → Press Down
- Add Action: Move → Set Vertical Speed
- Set vertical speed to
8
Event: Key Release Down Arrow
- Add Event → Keyboard → Release Down
- Add Action: Move → Set Vertical Speed
- Set vertical speed to
0
Event: Collision with obj_wall
- Add Event → Collision → obj_wall
- Add Action: Move → Bounce (no configuration needed — it always bounces off solid objects)

- Create a new object named
obj_ball - Set the sprite to
spr_ball
Event: Create
- Add Event → Create
- Add Action: Move → Start Moving (Direction)
- Check one diagonal box in the 3x3 direction picker (not straight up or down)
- Set speed to
6
Event: Collision with obj_paddle_left
- Add Event → Collision → obj_paddle_left
- Add Action: Move → Bounce (no configuration needed — it always bounces off solid objects)
Event: Collision with obj_paddle_right
- Add Event → Collision → obj_paddle_right
- Add Action: Move → Bounce (no configuration needed — it always bounces off solid objects)
Event: Collision with obj_wall
- Add Event → Collision → obj_wall
- Add Action: Move → Bounce (no configuration needed — it always bounces off solid objects)

Goals are invisible areas behind each paddle. When the ball enters a goal, the opposing player scores.
- Create a new object named
obj_goal_left - Set the sprite to
spr_goal - Uncheck "Visible" - the goal should be invisible
- Check "Solid"
- Create a new object named
obj_goal_right - Set the sprite to
spr_goal - Uncheck "Visible"
- Check "Solid"
Go back to obj_ball and add these events:
global.p1score/global.p2score are custom named variables, one per
player — the built-in Set Score action doesn't fit here, since it
always writes to the single built-in score, with no way to point it at a
variable name. Set Variable is the real action for a custom named
variable and supports a global scope:
Event: Collision with obj_goal_left
- Add Event → Collision → obj_goal_left
- Add Action: Move → Jump to Start Position (resets the ball)
- Add Action: Control → Set Variable
- Variable:
p2score - Value:
1 - Scope:
global - Check "Relative" (adds 1 to current score)
- Variable:
Event: Collision with obj_goal_right
- Add Event → Collision → obj_goal_right
- Add Action: Move → Jump to Start Position
- Add Action: Control → Set Variable
- Variable:
p1score - Value:
1 - Scope:
global - Check "Relative"
- Variable:

- Create a new object named
obj_score - No sprite needed
Event: Create
- Add Event → Create
- Add Action: Control → Set Variable
- Variable:
p1score, Value:0, Scope:global
- Variable:
- Add Action: Control → Set Variable
- Variable:
p2score, Value:0, Scope:global
- Variable:
Event: Draw
- Add Event → Draw
- Add Action: Draw → Draw Text
- Text:
Player 1: - X:
10 - Y:
10
- Text:
- Add Action: Draw → Draw Variable
- Variable:
global.p1score - X:
100 - Y:
10
- Variable:
- Add Action: Draw → Draw Text
- Text:
Player 2: - X:
10 - Y:
30
- Text:
- Add Action: Draw → Draw Variable
- Variable:
global.p2score - X:
100 - Y:
30
- Variable:

- Right-click on Rooms and select Create Room
- Name it
room_pong - Set the room size (e.g., 640x480)
Place the objects:
-
Walls: Place
obj_wallinstances along the top and bottom edges of the room -
Left Paddle: Place
obj_paddle_leftnear the left edge, centered vertically -
Right Paddle: Place
obj_paddle_rightnear the right edge, centered vertically -
Ball: Place
obj_ballin the center of the room -
Goals:
- Place
obj_goal_leftinstances along the left edge (behind where the paddle is) - Place
obj_goal_rightinstances along the right edge
- Place
-
Score Display: Place
obj_scoreanywhere (it doesn't have a sprite, it just draws text)
Room Layout Example:
[WALL WALL WALL WALL WALL WALL WALL WALL WALL WALL]
[GOAL] [PADDLE_L] [BALL] [PADDLE_R] [GOAL]
[GOAL] [PADDLE_L] [PADDLE_R] [GOAL]
[GOAL] [GOAL]
[WALL WALL WALL WALL WALL WALL WALL WALL WALL WALL]

- Click Run or press F5 to test your game
- Player 1 uses W (up) and S (down)
- Player 2 uses Up Arrow and Down Arrow
- Try to hit the ball past your opponent's paddle!
Make the ball faster each time it hits a paddle. speed isn't usable here
directly — on this engine it's the sprite's animation rate, not movement
speed — so track the ball's own speed in a custom variable instead:
- In
obj_ball's Create event, add Control → Set Variable (Variable:ball_speed, Value:6) right after the Start Moving action. - In each paddle-collision event, after the Bounce action, add
Control → Set Variable (Variable:
ball_speed, Value:0.5, Relative checked), then Move → Set Speed with Value:self.ball_speedto apply the new speed while keeping the current direction (Bounce already flipped it).
Add sounds when:
- The ball hits a paddle
- The ball hits a wall
- A player scores
Add a check in the Draw event:
- If
global.p1score >= 10, display "Player 1 Wins!" - If
global.p2score >= 10, display "Player 2 Wins!"
| Problem | Solution |
|---|---|
| Ball goes through paddle | Make sure paddles have "Solid" checked |
| Paddle doesn't stop at walls | Add collision event with obj_wall |
| Score doesn't update | Check that variable names match exactly (global.p1score, global.p2score) |
| Ball doesn't move | Check the Create event has the movement action |
Congratulations! You've created a complete two-player Pong game! You learned:
- How to handle keyboard input for two different players
- How to use Key Release events to stop movement
- How to make objects bounce off each other
- How to use global variables to track scores
- How to display text and variables on screen
- Beginner Preset - Overview of beginner features
- Tutorial: Breakout - Create a brick breaker game
- Event Reference - Complete event documentation
- Full Action Reference - All available actions