Как создать платформер

3

Index

Tagged

Contributors

Stats

90,893 visits, 122,520 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 17 May, 2017. Last updated 25 Feb, 2019

Adding behaviors

Construct 2 comes with lots of behaviors. These make your objects work in pre-defined ways, which often saves loads of time. It's possible to re-do everything the behaviors do in the event system, but it is often difficult and time consuming to do that. That's why behaviors are really handy to get your game up and running quickly!

The Platform behavior can take care of the complexities of platform movement for us. However, there's one important tip for using it: the behavior should be applied to an invisible rectangle object, and the player positioned on top. The Platform behavior works much better if the object with the behavior doesn't animate, since changing animation frame can leave the object partly sticking in to a wall which can confuse the Platform behavior. Also, it avoids silly collision situations like your player hanging off a ledge by their nose or something they're holding.

So we need to make an invisible square for the movement first. Double-click the layout to add a new sprite again, and this time import a square like below. (Right-click and 'save as' if you need it.)

As before, we should have the origin at the bottom. So click Set origin and image points again and press 2 (or use the quick assign menu) to position the origin at the bottom.

Close the image editor. You should now see it in the layout. Resize it to roughly the same size as the player's body as shown below - this size is 53x107.

Rename this object to PlayerBox since it's the box for movement and collision testing for the player. Also, in the Properties Bar, set Initial visibility to Invisible since we don't want to see it.

We also want to give the Platform movement to the PlayerBox object for more reliable collision detection. Still in the PlayerBox's properties, click Add / Edit by Edit behaviors in the properties bar. In the dialog that appears, click the green plus button.

Double-click the Platform behavior.

You should see that some new properties for the platform movement have appeared in the Properties bar. You can tweak the movement settings like speed and acceleration. Let's make the jumps a little bit more snappy. Set the Jump strength to 1100 and the Gravity to 2500.

We also want the screen to follow the player, so click the green plus again and add the Scroll To behavior.

Once you've added both behaviors, close the Player behaviors dialog.

Adding the Solid behavior

The platform movement needs to know what objects it can land on. The player will fall through any objects which don't have the Solid behavior. So this time select the Tile sprite and add a behavior for it, this time choosing the Solid behavior.

We just now need to position the player on top of the PlayerBox. Switch to Event Sheet 1. This is where we define the game's logic using Construct 2's event system.

  • 3 Comments

  • Order by
Want to leave a comment? Login or Register an account!