Text input using TextBox (and invisible TextBox)

  • 37 favourites

Index

Attached Files

The following files have been attached to this tutorial:

.capx

textbox-input.capx

Download now 83.99 KB

Stats

9,548 visits, 22,350 views

Tools

What you will need for this tutorial

Introduction

Sometimes we need to let the players type some things into our game. Whether it's just a name for controlled by player character, winners name for high score at end of the level or even entire text based adventure game.

In Construct 2 there are many paths to achieve that task. Some of them are easy and some of them can take up to xx numbers of events.

In this tutorial we will focus on two of that paths. Easy one and bit more complicated, but still quite easy to understand.

The easy way

Preparation

The fastest and easiest way to let the player input some text, numbers or special characters into our game is to use Text box.

To do that, we will need three objects:

Keyboard - for player to input data to our game

Text box - to receive that data

Text - to display it on the screen.

Let's add these object to our layout. If you want you can change the font, size and color of Text object to whatever you want. We will keep it all as default. One thing to remember is that Text box Type must be set to Text, which is by default.

Action

We need only one.

Execution

That's it! Here's the results.

How does it work?

Every tick (about 60 times a second - practically always) when Text box object is selected and player will press any key on the keyboard, Text box will interpret that key and send it to Text object to display it on screen.

Ok. But what if I don't want to select any Text boxes? I just want to run my game and start typing!

Fair enough. We have to add one more action to our event.

Now Text box is always selected (focused) and you can start typing whenever you want!

  • 0 Comments

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