Hi guys… this is easy :s how can i make a dialog system?.. I wanna say write dialogs in a text file and insert them inside the game. Actually i have a system that load the dialogs and show them at the screen but, how can i do for “dialog jumps” i.e “First” show the first ten lines of dialogs, and after you need press enter to show more lines. :S How can i do that?
Well I’m not entirely sure how you want it to work but I’d just save everything as string variables, then load them into a JTextArea and put in an actionlistiner that changes the displayed message whenever the user presses the enter key.
I thought to use an array of strings to do it but i’m not sure. And i’m using it inside my game like the classic dialogs of Zelda or Pokemon.
In .properties file:
Dialogfor(insert name): Bla BLa BLA!!!
;D
first, what technologies are u using? Java2D or other? because the solution can give yoou completely different answers
for Java2D for example exists already API to support text management
but i f you are using UI component (Jtext etc…) is a completely different story.
Ok hire i will suppose that you are using JAva2D.
in this case you can find hire the official tutorial of the Oracle that show how to use the text in a Java2D graphic context
they are no more of 4-5 capiton very easy to undestand
http://docs.oracle.com/javase/tutorial/2d/text/index.html
what you have to look is this caption
http://docs.oracle.com/javase/tutorial/2d/text/drawmulstring.html
it will solve your problem to fix in you dialog box (drawing area) the text that you want to insert
instead regarding the way to insert dialog box that evolve the internal text after return press, can be easy and there are 1000 solution, but each one of this solution will be incorrect if it is not easy adaptable to the framework that you implemented.
for example if u have the text in the file you can do like this
- 1-load the text that you want to print and transform in a array of chars
- 2-give this array as parameter to your dialog box
- 3-the dialog box contain an internal state that is the index where to start to use the character in the array, for example when it will start for the first time the index will be 0,
- 4-the dialog box print the x characted that are possible in concordance with its size and update the index
- 5-at each press enter continue the iteration 3 and 4 until the text is finish
but be carefull this solution has a problem for example its eat chatacters!!!
immagin that you want to write this string in your dialog
“test string, i like write text in java” that is 38 chars
and your dialog write only 10 characters the result after any press return is
1 return “test strin”
2 return “g, i like w”
3 return “rite text i”
4 return “n java”
so take care to raffinate the algorithm to don’t cut the words, for exaple you can use a StringTokenizer to reconize words
bye
okay i understand it but now i have a tiny question. Can i put a dialog between 2 “characters” in the same file or i must create a file for every “single dialog”?