Book Image

Construct 2 Game Development by Example

By : John Bura
Book Image

Construct 2 Game Development by Example

By: John Bura

Overview of this book

Table of Contents (16 chapters)
Construct 2 Game Development by Example
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Where to Go from Here
Index

Controlling a sprite with the keyboard


Let's add some game logic to the game. Double-click on the screen in the first layout and add the keyboard and mouse objects, as shown in the following screenshot. This allows us to use the Keyboard and the Mouse in our game.

Let's set up the game logic:

  1. We need to make the player move with the WASD control and rotate to the mouse location. Click on the player and add the behavior.

  2. Once you see this dialog box, click on the plus sign to add a behavior.

  3. Scroll down and add the 8Direction behavior:

  4. Once you have added the 8Direction behavior, it should appear just like the preceding screenshot. Exit this window and go to the layout.

What we want is for the player to use either the arrow keys or the WASD controls to move around. It's good to have both, as players have different preferences. The following are the steps to do so:

  1. First, we have to change the eight directions to four. You can have a game with the full eight directions, but four is a little easier...