how to get user input and stopping event propagation
Shri

Gio,

 

I have two questions:

1. How do you get user input for a game.

For example, say at the start of the game, I want to user to enter their name, so that messages in the game can have their name on it. It looks like I would have to do it in the web page and then input it to the game via the appData parameter of the init function ?  But I was wondering if there was another way to do it inside the game (wade app) itself ?

 

2. When I load a splash screen at the beginning of my games, I set it up as scene object which waits on a mouse down/touch event. Then when I get the event, I remove the splash scene object and the game runs. However, it seems that this mouse down then propagates into the game - causing the character to move to where the user clicked the start event. I am returning false from the splashObject.onMouseDown handler, but that doesn't work. Is there another way I should be handling this i.e. stopPropagation ? and if so, could you include a snippet ?

 

thanks for your help

 

cheers

All 2 Comments
Gio

Hi

 

1. The easiest way to do this cross-platform is to use JavaScript's prompt function.The problem is, it isn't very elegant and may not fit with the look and feel of the interface of your game. But this is generally a bit tricky. I have written a behavior class for this (which we used for Zirma), and I do intend to clean it up and share it at some point, but unfortunately this isn't something I can spend time on right now. I will share it at some point though, I promise :) You could use a DOM element (even when the game is running), such as an input box, but then scaling it up and down in the same way as your game (via CSS) isn't possible. On the other hand, reliably capturing all the relevant keyboard events on a virtual element in the canvas is a bit difficult on some platforms (Windows phone, for example, is terrible in that respect). So in an ideal world you would have to do different things on different platforms, and this is what my behavior is doing.

 

2. You need to return true to indicate that you are processing the event and want to stop its propagation.

Shri

Gio,

 

1. Thanks for the info, I guess I will just have the user input their name bein the web page before the game runs for now.

 

2. I found my problem (because returning true or false didn't matter). I was catching mouseDown in the splash screen and then the player moves on mouseClick. By making these all the same mouseClick, the problem went away.

 

cheers

Post a reply
Add Attachment
Submit Reply
Login to Reply