Create and Customize Enemy Sprites - GameMaker Studio 2 Tutorial

Create and Customize Enemy Sprites - GameMaker Studio 2 Tutorial

Table of Contents:

  1. Introduction
  2. Creating Enemy Sprites
  3. Designing the Enemy Sprite
  4. Creating Enemy Objects
  5. Placing Enemies in the Game
  6. Making the Enemies Move and Bounce
  7. Handling Collisions with Walls
  8. Solving Issues with Enemy Sticking
  9. Adding Interaction with the Player
  10. Conclusion

🎮 Creating Enemy Sprites

In this section, we will learn how to create enemy sprites for our game. To start, open the sprites folder and select the level one folder. Right-click on the enemies folder (create one if it doesn't exist) and choose "Create" followed by "Sprite". Name the sprite "s_enemy_ff" (ff standing for French Fry) and click "Enter".

Now, click on "Edit Image" to start drawing the French fry enemy sprite. Use the line tool and select a color slightly darker than yellow for the French fry's Outline. You can adjust the shade using the color picker or sliders. Once you're satisfied, draw the French fry Shape by making a continuous line using the line tool. Feel free to make the sprite slightly bigger if needed.

Next, add some details to the French fry sprite. Create a new layer and select the Pencil tool. Choose a smaller brush size and draw two pairs of eyes using the white color. Finally, add a mouth by drawing a line with a lighter gray color.

🔧 Creating Enemy Objects

Now that we have our enemy sprites, it's time to create enemy objects. Open the objects folder and select the level one folder. Right-click on the enemies folder and choose "Create" followed by "Object". Name the object "o_enemy_ff" (ff referring to French Fry).

Bind the sprite we created earlier to the object. Go back to the room and add a new layer. Rename the layer as "enemy" and drag and drop the enemy objects onto the room. Adjust their positions on the GRID if necessary.

⚡ Making the Enemies Move and Bounce

To make the enemies move and bounce between walls, we'll add some code to the o_enemy_ff object. Double-click on the object to open its properties and click on the "Add Event" button. Select "Step" from the list.

In the step event, we'll add a variable called "enemy_speed" with a value of 3. This variable represents the speed at which the enemies move. Next, in the code box for the step event, use the following code:

x += enemy_speed;

This code adds the enemy_speed value to the x position of the enemy, making it move horizontally to the right.

🚧 Handling Collisions with Walls

To handle collisions between enemies and walls, we'll add a collision event between the o_enemy_ff object and the wall object. When a collision occurs, we want the enemy to bounce back in the opposite direction. In the o_enemy_ff object properties, click the "Add Event" button and select "Collision" followed by "with the object a_wall".

In the collision event code box, add the following code:

enemy_speed *= -1;

This code multiplies the enemy_speed variable by -1, changing its sign. If the enemy_speed is positive, it becomes negative, and vice versa. As a result, the enemy changes its direction and starts moving towards the opposite side.

✨ Solving Issues with Enemy Sticking

Sometimes, enemies may stick to the walls when colliding. This can be resolved by ensuring that the collision occurs on solid parts of the wall object. Avoid using walls with splits or gaps in the areas where the enemies collide. By using solid areas, the enemies will bounce off correctly.

🤝 Adding Interaction with the Player

In the next section, we'll explore the interaction between enemies and the player. We will define what happens when they collide and how it affects the player and the score.

🎉 Conclusion

In this article, we have learned how to create enemy sprites, design them, create enemy objects, place them in the game, make them move and bounce, handle collisions with walls, and resolve issues with enemy sticking. In the next section, we will explore the interaction between enemies and the player. Stay tuned!


Highlights:

  • Learn how to create enemy sprites for your game
  • Design and customize the appearance of the enemy sprite
  • Create enemy objects and place them in the game room
  • Make the enemies move and bounce between walls
  • Handle collisions between enemies and walls
  • Resolve issues with enemies sticking to walls
  • Add interaction between enemies and the player

FAQ:

Q: How do I create enemy sprites? A: To create enemy sprites, open the sprites folder and select the level one folder. Right-click on the enemies folder (create one if it doesn't exist) and choose "Create" followed by "Sprite". Name the sprite and start drawing your enemy using the available tools.

Q: How do I make enemies move and bounce? A: To make enemies move and bounce, add a step event to the enemy object and use code to change its position. Additionally, add a collision event between the enemy and walls to make them bounce back when they collide.

Q: What should I do if enemies stick to the walls? A: If enemies stick to the walls, check if the collision occurs on solid parts of the wall. Avoid using walls with splits or gaps where the enemies collide. Ensuring solid collision areas will resolve the issue.

Resources:

Most people like

Find AI tools in Toolify

Join TOOLIFY to find the ai tools

Get started

Sign Up
App rating
4.9
AI Tools
20k+
Trusted Users
5000+
No complicated
No difficulty
Free forever
Browse More Content