Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
happymeal
Visitor

Help with drawText

Hello,

I'm new to Roku development and using Brightscript, but hopefully I'm not asking something that is too stupid. I've scoured the forums and documentation before asking and not come up with any answers yet. A lot of the examples that come with the SDK cover moving sprites, but none really appear to cover text

First of all, just a general outline of what I'm trying to achieve. I want to create my own text fields using an roScreen + drawText functions. I immediately noticed that the documentation stated drawText was expensive to render. What is the alternative to using drawText if my text is not static? I'm basically out to create something similar to the roPosterScreen without being restricted by its layout. i.e. when you use the arrow keys to move through options, the text updates.

I've managed this ok, however have come across my first stumbling block. The text spans across multiple lines, however drawText does not seem to want to draw it over more lines. Is it a case of having to draw each line of text independently using drawText? if so, are there any easier text components to use that handle the word wrapping for you? I've also noticed, it does not recognise the new lines or '\n' in my text.

I'll try not to add too many questions in my first post, but this would be a good start. Thanks in advance for anyone replying.
0 Kudos
6 REPLIES 6
RokuJoel
Binge Watcher

Re: Help with drawText

Hi,

I would decide how wide your text field should be, and take field.mid(maximum) and draw a second line of text there. It might be "expensive" in render time, but for what you are doing it is more than fast enough.

If you notice the existing posterscreen object doesn't wrap text either, it splits it into ShortDescriptionLIne1 and ShortDescriptionLine2.

if you want to put a whole paragraph of unknown length, you would just have to do a little calculation and split it when you reach the widest spot.

You could also render all the text at once onto sprites instead of drawing it dynamically. The functions of roFont and roFontRegistry should help you to determine the vertical spacing with which to draw your text.

- Joel
0 Kudos
kbenson
Visitor

Re: Help with drawText

"happymeal" wrote:
Hello,

I'm new to Roku development and using Brightscript, but hopefully I'm not asking something that is too stupid. I've scoured the forums and documentation before asking and not come up with any answers yet. A lot of the examples that come with the SDK cover moving sprites, but none really appear to cover text

First of all, just a general outline of what I'm trying to achieve. I want to create my own text fields using an roScreen + drawText functions. I immediately noticed that the documentation stated drawText was expensive to render. What is the alternative to using drawText if my text is not static? I'm basically out to create something similar to the roPosterScreen without being restricted by its layout. i.e. when you use the arrow keys to move through options, the text updates.


Put it in context. Think of it like this: "DrawText is slow to render for the roScreen system, which was designed to make it possible to write games. It may make it hard to achieve 30 fps if you draw a lot of text." That probably doesn't affect you much when using it for a menu.


I've managed this ok, however have come across my first stumbling block. The text spans across multiple lines, however drawText does not seem to want to draw it over more lines. Is it a case of having to draw each line of text independently using drawText? if so, are there any easier text components to use that handle the word wrapping for you? I've also noticed, it does not recognise the new lines or '\n' in my text.

I'll try not to add too many questions in my first post, but this would be a good start. Thanks in advance for anyone replying.


I haven't done a lot with DrawText, but if there's nothing easier, you could work it out with roFontMetrics to determine how large the text is and write your own line wrapping utilities.
-- GandK Labs
Check out Reversi! in the channel store!
0 Kudos
happymeal
Visitor

Re: Help with drawText

Thanks both for the feedback and suggestions. I've written my own textfield object which breaks texts across multi-lines. Rendering runs smoothly even drawing multiple lines of text to the screen every frame. I'll next look into rendering text onto sprites as Joel suggested so as to optimise things further. Just on this front, I've not spent too long trying different solutions but am I right in saying I can treat an roBitmap object much like an roScreen and use my drawTexts\drawRects to that? Then I would use drawObject to draw that bitmap to my roScreen?

Thanks
0 Kudos
TheEndless
Channel Surfer

Re: Help with drawText

"happymeal" wrote:
Just on this front, I've not spent too long trying different solutions but am I right in saying I can treat an roBitmap object much like an roScreen and use my drawTexts\drawRects to that? Then I would use drawObject to draw that bitmap to my roScreen?

You are correct. All three, roScreen, roBitmap, and roRegion implement the ifDraw2D interface. If you're trying to achieve a high framerate, be aware that drawing to a bitmap first, then drawing that bitmap to the screen will reduce the framerate if you're doing it every frame. On the flip side, if you're only drawing to the bitmap on the first frame and then reusing what was drawn, it should significantly improve the framerate.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
happymeal
Visitor

Re: Help with drawText

"TheEndless" wrote:
"happymeal" wrote:
Just on this front, I've not spent too long trying different solutions but am I right in saying I can treat an roBitmap object much like an roScreen and use my drawTexts\drawRects to that? Then I would use drawObject to draw that bitmap to my roScreen?

You are correct. All three, roScreen, roBitmap, and roRegion implement the ifDraw2D interface. If you're trying to achieve a high framerate, be aware that drawing to a bitmap first, then drawing that bitmap to the screen will reduce the framerate if you're doing it every frame. On the flip side, if you're only drawing to the bitmap on the first frame and then reusing what was drawn, it should significantly improve the framerate.


Thanks TheEndless - yes drawing once and redrawing the single bitmap. Has worked and improved framerate dramatically.
0 Kudos
Komag
Roku Guru

Re: Help with drawText

I found another text wrapping function in this thread:
viewtopic.php?f=34&t=64824

but maybe the one you wrote, happymeal, works better?

"happymeal" wrote:
I've written my own textfield object which breaks texts across multi-lines. Rendering runs smoothly even drawing multiple lines of text to the screen every frame.
This is the part that sounds perfect - how do you actually do this?

And I'm not quite sure what
"happymeal" wrote:
rendering text onto sprites
even means, let alone how to do it, or even why! Would this increase performance somehow?

I'm attempting to make a very text-heavy game. I'm still learning this stuff, but I'm not a programmer, just a tinkerer who's made a few game mods and stuff.
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.