In Game Name

Hey guys/gals, I was wondering if there was a way to create an in-game name. I’ve tried searching around to see how to do it, but I have no luck. Any help will be appreciated  :slight_smile:

Can you provide more context? What is this name for? Is it something the user needs to be able to enter?

Well this name will basically be the users, username. So once the app opens it’ll ask for your username and once entered it is saved in the main page of the game.

You will probably need a scene in your game (could be a settings scene). You will want to have a label (display.newText()) and a text field (native.newTextField()).  Once the user submits the name, then you can store it in a variable.

There are a couple of sample apps in the SampleCode/Interface folder that shows you how to do text fields. There should be examples in the API docs for native.newTextField() showing you how to use it.

Rob

How would I approach this? Would this mean I would have to require this file into my gamescreen where it will show the username?

In the game I’m making I already have a “gamesettings” screen where I allow the user to turn music on and off as well as sounds on and off. I needed a player name, so I create a generic player name “New Player” or some such that I use if they don’t visit the settings screen and fill it out. I added my label and native.newTextField() on that screen.

You may choose to prompt users the first time the app is run to enter their name. Then save the information out to system.DocumentsDirectory (many different ways to do this too). But you should provide them a way to change it.

There are probably many other ways to handle it. Perhaps you want to defer the name setting until you actually need it. For instance if you need to provide the name to a high score system, when you go to set the high score, if the name hasn’t been set, popup a screen to collect it at  that point, then save everything.

Or you could go old school arcade game and actually put the text field in the high score list and have them type in their name or initials when they make the top 10 scores.

It’s all up to you when and where you want to ask for this information. 

Rob

Can you provide more context? What is this name for? Is it something the user needs to be able to enter?

Well this name will basically be the users, username. So once the app opens it’ll ask for your username and once entered it is saved in the main page of the game.

You will probably need a scene in your game (could be a settings scene). You will want to have a label (display.newText()) and a text field (native.newTextField()).  Once the user submits the name, then you can store it in a variable.

There are a couple of sample apps in the SampleCode/Interface folder that shows you how to do text fields. There should be examples in the API docs for native.newTextField() showing you how to use it.

Rob

How would I approach this? Would this mean I would have to require this file into my gamescreen where it will show the username?

In the game I’m making I already have a “gamesettings” screen where I allow the user to turn music on and off as well as sounds on and off. I needed a player name, so I create a generic player name “New Player” or some such that I use if they don’t visit the settings screen and fill it out. I added my label and native.newTextField() on that screen.

You may choose to prompt users the first time the app is run to enter their name. Then save the information out to system.DocumentsDirectory (many different ways to do this too). But you should provide them a way to change it.

There are probably many other ways to handle it. Perhaps you want to defer the name setting until you actually need it. For instance if you need to provide the name to a high score system, when you go to set the high score, if the name hasn’t been set, popup a screen to collect it at  that point, then save everything.

Or you could go old school arcade game and actually put the text field in the high score list and have them type in their name or initials when they make the top 10 scores.

It’s all up to you when and where you want to ask for this information. 

Rob