Scrollable Textboxes?

kiwixoats

  • Posts: 104
Is this possible (scrollable textboxes with that black scrollbar) in stencyl? Or is there a way to achieve it with Xcode + my stencyl project? I need this because there are large amounts of text in my game and I want the text to be in a scrollable box so that it doesn't take up all of the space on the screen.

Thanks.

Luyren

  • *
  • Posts: 2705
It is possible without code. I have a logic that can display in scrollable textbox items from a list. I can post it here, if you think it can be useful.
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.
Twitter

kiwixoats

  • Posts: 104
That's awesome, yes please!

Thank you.

Luyren

  • *
  • Posts: 2705
This is the logic I use. You'd have to replace some stuff, and I'll do my best to explain everything. I'll separate the explanation based on the comment blocks from the attached image, but keep in mind it's not exactly easy stuff.

As a heads up: I'm using this to drawn the inventory of an actor on screen. So everytime you see "Inventory", it should be the list that holds the text you want to display. The other list, "Item Position Display" holds how many items from the inventory list will be displayed, and their position on screen. So if "Item Position Display" has 3 items, 3 lines of text will be displayed on screen. This list holds the coordinates to draw the text in the format "X,Y", so I use the "split" block to get the X and Y coordinates.

Scrollbar
This handles drawing the actual scrollbar. In this case it's only a vertical scrollbar. The first blocks set the color of the background of the scrollbar, and draws it. Then, it sets the color for the actual scrollbar.
Our first "if" statement compares the number of items in inventory (or the maximum amounts of lines of text) against the "Item Position Display". If it's less, it will draw the scrollbar using the maximum height. Otherwise, it will check what percentage the "Item Position Display" represents from the total number of lines you want to display. So for example, if "Item Position Display" has 3 items, and your total number of lines is 30, it will draw only 10% of the total number of lines. This if statement multiplies the maximum scrollbar height by this percentage. If it's bigger than the minimum scrollbar height, it will do some math to draw the scrollbar at the right position, with the right height. If it's smaller than the minimum, it will draw it with a height of 1 pixel.

Show items
It begins by setting a loop through the "Item Position Display" list. The first if is something I do to set which font to use, you shouldn't worry about that.

Inventory
Within the loop we started above, we'll draw every line of text. Each line will be drawn at the positions we define in the "Item Position Display" list.

This part has a new elemtn: the "Initial Display" attribute. It's a number that is increased or decreased when we scroll the text. I'm using two draw blocks because I'm drawing the inventory item and the amount, you'd only have to use one.

To select the text to draw, you'd use:

get item # [(current loop count) + (Initial Display)] from [Your list]

Then we split the current item from the Item Position List to get the X and Y position to draw.

Description
You can ignore this.

NextItem
This events increases the "Current Inventory Item", in your case it would be something like the current line of text. This might not be necessary in your case, so you can just increment the Initial Display.

Maximum and Minimum current inventory items values
This goes in the "Updating" event. In your case, it would be used to set the maximum and minimum values of "Initial Display".

Well, that's about it. Any questions, feel free to ask, and good luck with it.
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.
Twitter

kiwixoats

  • Posts: 104
Thanks a lot; I may have questions later because I haven't yet implemented it, but once again thanks.

maek0witzki

  • Posts: 5
gladly there is already an answer.
I wouldn't have to google any other :)