2

Sorry I'm a bit new to libgdx (really liking it so far!), so might be a bit starter question

I am implementing a dialogue box class for my RPG game. Basically I am having it display character by character like you see in Final Fantasy games when people are talking. I got it working really well with word wrapping by using the BitmapFontCache class. My next step is to implement "paging". (i.e You pass a string to the dialogue class to display and it determines what parts of the string can fit in each page of dialogue). I'm having a bit of trouble with this without resorting to calculating my own word wrapping.

Is there a function that I can pass the constraints of my dialogue box (say a rectangle) and get back the portion of the string that would fit in that constraint? (taking into account word wrapping + end lines and the like). I can loop through character by character and use getWrappedBounds (and then stop once it goes over my constraint height) but I feel like I would still need to account for word wrapping when getting the string portion.

Any ideas?

Mr. Alien
  • 153,751
  • 34
  • 298
  • 278
Arbel
  • 425
  • 8
  • 26

1 Answers1

1

I've got two answers for you-

First, I think this function does what you're looking for: addWrappedText(java.lang.CharSequence str, float x, float y, float wrapWidth) (javadoc).

Second, you might want to look into using the built-in GUI components instead of building your own. I'd recommend you look at scene2d ui, which is a library that comes with libgdx and allows you to quickly put together flexible GUIs. It will take a little bit of work to set up, but it gives you a lot of options later since you get things like skins and ninepatches for free this way, so I highly recommend you look at it.

John
  • 1,440
  • 1
  • 11
  • 18
  • Hi John thanks for the reply. Do you mean by adding character by character and then checking when the bounds exceeds? Wouldn't I still need to account for word wrapping myself? (Say when it's in the middle of a word and exceeds the bound, I want that word to wrap to the next page). – Arbel Feb 12 '14 at 10:27