Beginner's guide to Construct 3

1940

Index

Contributors

Stats

1,312,017 visits, 3,809,879 views

Tools

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 20 Sep, 2017. Last updated 24 Jun, 2024

Adding behaviors

Behaviors are quick ways to make an object act a certain way. For example, you can add a Platform behavior to an object, and the Solid behavior to the floor, and you instantly can jump around like a platformer game. You can usually do the same in events, but behaviors are much quicker! Construct has a wide range of behaviors, but here are a few that we'll use in this tutorial.

  • 8 Direction movement: this lets you move an object around with the arrow keys. It will do nicely for the player's movement.
  • Bullet movement: this moves an object forwards at its current angle. It'll work great for the player's spells that they cast out. Despite the name, it'll also work nicely to move the goblins around - since all the movement does is move objects forwards at some speed.
  • Scroll to: this makes the screen follow an object as it moves around (also known as scrolling). This will be useful to keep the view centered on the player.
  • Bound to layout: this will stop an object leaving the layout area. This will also be useful on the player, so they can't wander off outside the game area!
  • Destroy outside layout: instead of stopping an object leaving the layout area, this destroys it. It's useful for our spells. Without it, spells would fly off the screen forever, always taking a little bit of memory and processing power. Instead, we should destroy the spells once they've left the layout.
  • Fade: this makes an object fade out, which we will use on the spark flashes.

Let's add these behaviors to the objects that need them.

How to add a behavior

Let's add the 8 direction movement behavior to the player. Click the player object to select it. In the Properties Bar, notice the Behaviors category. Click the Behaviors link there. The Behaviors dialog for the player will open.

The Behaviors dialogThe Behaviors dialog

Click Add new behavior in the behaviors dialog. Double-click the 8 direction movement to add it.

Adding the 8 direction behavior

Do the same again and this time add the Scroll To behavior, to make the screen follow the player. Then also add the Bound to layout behavior, to keep them inside the layout. The behaviors dialog should now look like this:

Player behaviors list

Close the behaviors dialog. Now try pressing Preview to run the game so far! Once the preview starts, notice you can already move around with the arrow keys, and the screen follows the player. You also can't walk outside the layout area, thanks to the Bound to Layout behavior. This is what behaviors are good for - quickly adding common features. We'll be using the event system soon to add custom features.

Adding the other behaviors

We can add behaviors to the other objects by the same method - select it, click the Behaviors link to open the behaviors dialog, and add some behaviors. Let's add these other behaviors:

  1. Add the Bullet movement and Destroy outside layout to the Spell object
  2. Add the Bullet movement to the Goblin object (because it just moves forwards as well, just at a slower speed)
  3. Add the Fade behavior to the SparkFlash object (so it gradually disappears after appearing). By default the Fade behavior also destroys the object after it has faded out, which also saves us having to worry about invisible SparkFlash objects clogging up the game.

If you run the game, you might notice the only thing different is any goblins you can see suddenly shoot off rather quickly. Let's slow them down to a leisurely pace. Select the Goblin object. Notice how since we added a behavior, some extra properties have appeared in the properties bar:

Bullet behavior properties

This allows us to tweak how behaviors work. Change the speed from 400 to 80 (this is in pixels travelled per second).

Similarly, change the Spell object's speed to 600, and the SparkFlash object's Fade behavior's Fade out time to 0.5 (that's half a second).

Create some more goblins

Holding Control, click and drag the Goblin object. You'll notice it creates another instance. This is another object of the Goblin object type.

Object types are essentially 'classes' of objects. In event sheets, you mainly deal with object types. For example, you might make an event that says "Spell collides with Goblin". This actually means "Any instance of the Spell object type collides with any instance of the Goblin object type" - as opposed to having to make a separate event for each and every goblin. We'll cover more on object types vs. instances later. For now, a good example to think about is different types of enemy are different object types, then the actual enemies themselves (which there might be several of) are instances of those object types.

Using Control + drag, create 7 or 8 new goblins. Don't place any too close to the player, or they might die straight away! Remember you can zoom out with Control + mouse wheel down if it helps, and spread them over the whole layout. You should end up with something a bit like this.

Goblins positioned in the layout

Now it's time to add our custom logic with Construct's visual method of programming - event blocks!

Next Tutorial In Course

How to Learn Construct 3? Next Steps for Beginners 51:05

Get started with Construct's built in examples and game templates

Disabled Comments have been disabled by the owner.