Introduction: Before starting a Game, always decide what this game is all about and things you will need to create a base of the game. “Hit the Ball” is a damn simple game, in which there will be two moving balls and you have to hit them with the cursor. With every hit you earn the points.



Sprites are just simple images. These are your game graphics that will be displayed on the screen.


So, sprites we need:

  1. A ball
  2. A wall

As you can see its pretty simple game, so the only things you need for the game is two sprites,



We just need two sounds, a Hit sound,  when the mouse will hit the ball and a background music.

  1. Hit sound
  2. Background music



You can select any background from Game Maker directory. I used this:



You have to create just 2 objects.


  1. Create a new object and name it obj_ball and in the sprite field, select spr_bat.


As you can see that there are two empty fields EVENTS and ACTIONS. In Events field you have to specify on which event what actions will takes place, those actions will go into ACTIONS filed. For example, if want to delete an object when we click Mouse Left button. Here When Mouse left button is pressed is an EVENT and Deleting the object is an ACTION.

  1. First thing we want is our ball to move in random directions. So from ADD EVENT choose CREATE. Drag MOVE FIXED
    from move tab.

Now you can place obj_ball in the room and run the game.

Select all the direction except middle one, and enter speed = 4.

  1. Since there are no walls to bounce back the balls, we have to create walls around the room so the balls don’t go outside the room.

    Create a new object and name it obj_wall. In the Sprite field, select spr_wall. You don’t have to add any events, because this object will only work as a block to stop the ball from going outside. Don’t forget to check Solid. We have checked Solid so that we can add a collision with the ball.


  2. Let’s add a collision with the wall, so ball bounce back when it hits the wall. So reopen obj_ball properties and from ADD EVENT choose Collision event with obj_wall.

  1. We want our ball to bounce when it collides with the wall, so there is already a predefined action for that. So select Bounce from move tab.

and enter:

If you set the parameter precise to false, only horizontal and vertical walls are treated correctly. When you set precise to true also slanted (and even curved) walls are treated correctly.

Now you can place walls in the room and test the code.

  1. Now we have to add Mouse events, So when the player hit the ball with cursor, we want three things to happen
    1. Play a hit sound
    2. Add 1 point in the score
    3. Send the ball to a random position so that it feels like that it’s a new ball


  1. So select Mouse left button from Add event.

In the action field start dragging Actions as per requirement.

a) Play a Hit sound

So drop Play sound from main1 tab.

Sound: snd_hit

Loop : false

b) Add 1 point in the score

Drop Set Score from Score

In its values, enter:

Don’t forget to check the Relative box, So Game Maker will add 1 point every time, when the cursor hits the ball. If we uncheck Relative, Game Maker will set the score to 1 every time Player hits the ball.


c) Send the ball to a random position


Select Jump to random from move tab and leave its value same.


Snap vert. = 0

Snap hori. = 0



d) Now since you have added all the requirements, but one more action you have to add with these three actions. Its Move fixed and enter the same values as before.


Explanation: We have added this action again, because when the ball will move at random position, we want our ball to move in different direction. If you will not add this action, then the ball will be placed at a random position, but it will move in the same direction in which it was moving before the Player hit it.


Now your game is ready to run. But before
we run it lets add a background to the room.


  1. Open the room properties you have created.

    Choose your desired background and check Visible when room starts. For reference you can see the picture attached below.


Congratulations! You have created your first game. Why not show it to your friends.

Congratulations! You created your first game. Your journey starts from here. Don’t give up. Start small and learn from everywhere.

Sujit Yadav

Sujit Kumar Yadav is a tech savvy who loves to explore about new technology. He is also passionate about animation and game development. He loves to write poems and to draw. He is a learner of life who loves travelling, meeting new people and dancing.

Comments ( 5 )
  1. shubham verma
    June 25, 2014 at 10:56 am

    Thanks sujit finally i have created my first game,I am highly thankful to you and your this post which help me alot.

  2. rkvieirauls
    June 22, 2015 at 10:01 am

    Hello. Superb site, very helpful indeed. It was a gateway for a ton of great content.
    On the article subject, am I missing something or the score wasn’t added to the game?

    Thanks and best of luck to you.

    • Sujit Yadav
      June 22, 2015 at 9:50 pm

      Thanks. Can you share your editable file or your code. So that I can look at the problem, you are facing.

  3. kinandev
    March 30, 2017 at 11:12 pm

    thank you for this tutorial and all good subject that you add in your blog
    plz my question is wht is the name of the software that you have use in this tutorial

    • Sujit Yadav
      March 31, 2017 at 8:55 am

      Thanks a lot. It’s Game Maker.

Leave a reply