Text input using TextBox (and invisible TextBox)

9
  • 46 favourites

Index

Attached Files

The following files have been attached to this tutorial:

.capx

textbox-input.capx

Download now 83.99 KB

Stats

13,560 visits, 31,019 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.

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!

  • 2 Comments

  • Order by
Want to leave a comment? Login or Register an account!
  • this was exactly what I needed! Cant wait to build upon this, so grateful :)

  • It is good, BUT try to hold Ctrl+A... This will show this terrible small text in the input form to the player because the text will be selected. What we can do with this?