简体   繁体   中英

How would I go about creating an input system like this?

I just started making a text-adventure in javascript this weekend.

I realized that the prompt input system can get really annoying, so I wanted to change over to a bar-input system that would collect input and store it in the "action" variable (see source), exactly like the one is this example I managed to find: http://iainlobb.com/dork/

SOURCE: http://dl.dropbox.com/u/96609235/mainfile.txt

(I know this might not be the most efficient way to make a text adventure, so I don't really want a lesson in the layout)

Steal his ;-)

Or if you want to make your own you basically just:

  1. An input with width="100%"; this will be the "bar-input"
  2. Attach a keypress event handler to that input, and listen for any enter key-presses that happen
  3. When that event fires, have your handler ... handle it (move the user in to the next room or whatever)
  4. Whenever you write more text out to the user, re-position the input (depending on the HTML/CSS you use, this might happen automatically).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM