Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: C#/XNA TypeWriter Engine  (Read 2748 times)

0 Members and 1 Guest are viewing this topic.
C#/XNA TypeWriter Engine
« on: February 26, 2012, 11:39:36 am »
  • *
  • Reputation: +12/-2
  • Offline Offline
  • Gender: Male
  • Posts: 4849
So, I am at the point where I need to create a text engine for U.N. Squadron.  Now, I have very little experience with making a text engine that works like a typewriter.  I only modified one once for my old Myth of Heroa project.  So, I decided to take what i know at this point and apply it to a basic new typewriting engine.  I am sure there are good ones already floating around the net, but I am trying to figure it out without copy/pasting someone's code.

Anyway, check attachment if interested(contains source).  It works great at it's current stage.  However, I do not understand how to implement a perfect wrap around feature.  Should I wait to add a new line if the TestString.ElementAt(charPosition) == " " (a space).?  But then what happens if the person using said engine decides to add some long ass word towards the end of their wrap around length?

Example:
Wrap around length of 30 characters.
String to be drawn: Surprisingly, the clever voracious behemoth....

The wrap around would hit in the middle of the word "voracious"...which means it would be drawn off the desired area.  Would I have to add code that checks the length of the next word once the wrap length is neared?

BTW, this post got changed 3 times before I finally posted it as I figured some stuff out as I went along.

« Last Edit: February 26, 2012, 12:22:44 pm by Theforeshadower »
Logged
  • Super Fan Gamers!
Re: C#/XNA TypeWriter Engine
« Reply #1 on: February 28, 2012, 09:04:41 am »
  • Minalien
  • *
  • Reputation: +10/-1
  • Offline Offline
  • Gender: Female
  • Posts: 2119
Quote
But then what happens if the person using said engine decides to add some long ass word towards the end of their wrap around length?
Trust me, you're not going to need to worry about that.

My suggestion is to break the text into a series of words, checking the length of each word against the width of the text area (I'd use a size in pixels rather than a character count, when possible). Let's assume a two-line, Pokémon-esque text system. Rather than going the route that many Game Maker fangame developers take (calling a textbox scripts with up to two lines passed to the script at a time), I'd send the entirety of a paragraph (separate handling only for things requiring or no longer requiring user input) at once, breaking it up where you specifically want it to start a new text box.

Then I'd break the sentence, as I suggested, into a series of words based on white space separation (spaces should really be all that's necessary, unless you want to account for line breaks), which would then be stored in an array of strings. I'd then calculate the length of each string as my text box is cycling through, keeping track of how many lines have been shown. On an odd number of total lines, I would automatically scroll to the next set (or in the case of Pokémon, clear the current text box and start at the top line again), while an even text box would have me present the player for a "press A to continue"-style prompt (like the blinking cursor).

Granted, with this method you'll also want to keep track of the beginning of each line (so that when you scroll or start anew, you start from the correct index within the string).

Anyway, hope that made sense, I'm kind of out of it between drowsiness and a cold.
Logged
Quote
There's such a double standard about religion in the modern world. Catholics can gather, wear white robes, and say "In nomine Patris, et Filii, et Spiritus Sancti" and be considered normal.

But if my friends and I gather, wear black robes, and say  "Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn", we're considered cultists.
  • Development Blog
Re: C#/XNA TypeWriter Engine
« Reply #2 on: February 29, 2012, 01:53:22 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 2245
Generally I would have an array containing all the characters, if I found a space character I would keep a record of it and if when going through the characters I went over my horizontal limit I would add the characters from after that space on to the next line. Now if I don't have a space on that line then I wrap it at the last character I can fit on there.

I will generally have what goes on what line figured out before it starts to be drawn.
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.068 seconds with 43 queries.

anything