Reader small image

You're reading from  Learning Construct 2

Product typeBook
Published inDec 2014
Reading LevelIntermediate
Publisher
ISBN-139781784397678
Edition1st Edition
Languages
Right arrow
Author (1)
Aryadi Subagio
Aryadi Subagio
author image
Aryadi Subagio

Aryadi Subagio is the second among seven brothers. He has loved video games ever since he was little, and he wanted to make his own game in his teenage years. This led him to pursue a Diploma in Computer Programming after he graduated from high school, where he spent years learning about software development techniques. He learned about game development from online sites, because at that time, there was no book on game development in Indonesia. After graduating, he immediately jumped into the world of game development. During this time, he made a few shooting games for the Flash Platform. After a year, he decided to gain more experience by working in a game studio; this is when he joined Esabra Studio. After working at Esabra Studio, he worked at Enthrean Guardian, a game studio based in Semarang. He has now quit working and is trying to set up his own studio. Aryadi has a passion for sharing his knowledge. He has written a lot of blog posts about game development on Indonesian and English sites. He also shares his knowledge on his own personal blog at http://daggio21.blogspot.com/.
Read more about Aryadi Subagio

Right arrow

Chapter 5. Making a Platformer Game

Welcome to this chapter! We covered a lot in the previous chapter: a new game object, a new behavior, sub-events, and an expression. These new things are among the most common ones you'd use in your project, no matter what game you want to make. Solid objects are used when you want to make obstacles and/or levels in your game, and expressions and sub-events are often used when you're making games with complex mechanics.

I will teach you to use the knowledge that you have gained until now to the next level: how to create a more complex game, a genre that's one of the most popular ones right now, and that's a platformer. We will use solid objects to design a level, and we'll create a Mario-esque coin box and a puzzle element. I will also teach you how to use physics in Construct 2.

In this chapter, we will learn:

  • How to prepare a level

  • How to use physics

  • How to join two objects

Preparing the level


Starting from this chapter, I will skip the game-designing part and immediately get down to the technical bits. This way, I can give you more detailed explanations about each topic. For now, let's create a new empty project on Construct 2 and a level like the one shown in the following screenshot:

This example level has all the basic needs of a platformer level. It has a ground to walk on, platforms to step on, and a floating box that contains a coin. It's a good habit to prototype game mechanics early on, so make the game space capable of testing out either one or all your systems quickly. All the sprites we use here are from the freebundle.zip folder under Sprites\Platformer pack\Base pack\Tiles. The Platformer pack folder has a lot of sprites fit for a platformer game; it is a good idea to use them in your game sometime in the future. There's one thing missing though: the character.

Setting up the character

Setting up our main character requires us to make a few animations...

Learning about physics


We will now discuss physics in Construct 2. To apply physics to an object, we only need to add a Physics behavior to it. All objects with the Physics behavior are referred to as physics objects. Physics is a complex subject, so I will only explain it briefly here to cover what you need to know to start experimenting with it.

If you still remember your physics class back in school, then this will be really useful here because the concepts are the same. We will create a third layout to demonstrate our physics object, so create a new layout and make it look like this:

As you can see, we used two solid objects that we used to build up our levels earlier. However, we will add one new sprite object here called rock; the sprite for the rock object can be found under Base pack\Items. The rock doesn't do anything for now, but we'll use it as a physics object, so let's add a Physics behavior to it (the Physics behavior can be found in the movement section when you add a behavior...

Joining two objects


I have given you examples of how to use forces and impulses to move physics objects around, but I haven't covered joints yet. Joints are used to join two objects together so that the distance between them is the same. We will make a bridge using joints, so, create a new layout and make it look like the one shown in the following screenshot:

The sprites for the bridge and the fence objects are located under the Tiles folder. Before continuing, check the bridge's collision polygon and fix it so that no lines will intersect each other, just like the buttonBlue object. You want to be careful when adding physics objects, as small sprites tend to have similar collision polygons.

Tip

Always look for collision polygons when adding an object you want to make a physics object, especially the ones with small sprites.

The fences and bridges are physics objects, but only the fences are immovable; the bridges are still movable, but we won't let them fall to the bottom. We will tie the...

Types of physics engines in Construct 2


Construct 2 has three kinds of physics engines it uses to run physics operations:

  • box2dweb: By default, Construct 2 uses the box2dweb version of the physics engine. The box2dweb version is based on the box2d physics engine; a physics engine is commonly used for native games. The box2dweb version is the JavaScript version of it that's intended to be used for web games.

  • box2dweb asm.js: This is the faster version of box2dweb. It uses emscripten (a technology from Mozilla) that takes C and C++ code and produces JavaScript, creating high-performance JavaScript code as a result. This is what's called asm.js, and the browsers that are optimized for asm.js can translate this code to enable fast performance that you'd get from native C and C++ codes. However, all this happens in your browser.

  • CocoonJS native: This is the physics engine optimized for CocoonJS wrapping. If you don't know about it, CocoonJS is a service that helps you wrap or package HTML5 games...

Summary


Physics is a complex subject, but we delved into it in this chapter. You learned how to animate the sprite with and without looping. You also learned about three new behaviors: Platform, Scroll To, and Bound to Layout. Moreover, you learned how to create a new layout in Construct 2 and how to change to the new layout in the game. You also know the three engines that power Construct 2's physics and when they should be used. You also learned that we can pick an instance individually using UID, instead of picking all the instances at once. Finally, you also learned how to use joints in physics objects.

Our understanding of making a game in Construct 2 has increased, but so far, we have not added any competitive aspect in our game. One of the examples of a competitive element in games is a leaderboard for gamers to compete with. So, we'll make this in the next chapter.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Learning Construct 2
Published in: Dec 2014Publisher: ISBN-13: 9781784397678
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Aryadi Subagio

Aryadi Subagio is the second among seven brothers. He has loved video games ever since he was little, and he wanted to make his own game in his teenage years. This led him to pursue a Diploma in Computer Programming after he graduated from high school, where he spent years learning about software development techniques. He learned about game development from online sites, because at that time, there was no book on game development in Indonesia. After graduating, he immediately jumped into the world of game development. During this time, he made a few shooting games for the Flash Platform. After a year, he decided to gain more experience by working in a game studio; this is when he joined Esabra Studio. After working at Esabra Studio, he worked at Enthrean Guardian, a game studio based in Semarang. He has now quit working and is trying to set up his own studio. Aryadi has a passion for sharing his knowledge. He has written a lot of blog posts about game development on Indonesian and English sites. He also shares his knowledge on his own personal blog at http://daggio21.blogspot.com/.
Read more about Aryadi Subagio