We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, I have a little problem. On a processing project for android, I have to display a lot of text on the screen. I use :
string myString = "lots of words";
textFont(myFont, 20);
text(myString, x, y);
but the performances are very low (5 fps). Does anyone has an advice for a best performance?
Thanks a lot, JM
Answers
Thanks, I tried to use textFont() in setup() only but that didn't change anything... I can't use PGraphics bcause my texts are not always at the same place. I forgot to tell I used boxes to draw the text, well I mean :
text(myString, x, y, width, height);
define lots.
i've had problems before (early apple macs) where the word-wrapping algorithm part of the text displayer would flood the cpu dragging down performance. it's non-trivial, especially with proportionally spaced fonts.
you can move PGraphics...
lots of words : almost 3000 characters...
think we're going to need a short, runnable example that shows the problem just so that we can check you're not doing something stupid and to save us having to guess implementation details.
OK, here's my code :
the problem is that in my full sketch, I don't have this single page but many. I put each one in a separate void and text size and align are different in almost every page.
Surely the entire String doesn't fit on your screen. Couldn't you figure out what part of the String is visible, make a much shorter substring, and just display the substring?
Well, I'd rather not. I'd prefer to display my text with the scrolling I use. What I don't understand is that in Processing mode, this sketch runs at 60fps and in an Android device, it falls down at around 5 or 10 fps depending on the device...
A string is an array of characters and arrays makes fall your frame rate especially full of space like 3k that needs to be run index by index on a repeatable mode like inside the draw method. The pushMarix and popMatrix to make an illusion of movement, moving images, also decrease the framerate. Maybe the mobile device have less memory/processing hardware capabilities than the computer. You are using a default letter, there are more options.
Thanks Infsys,
"3k" : what's that?
"You are using a default letter, there are more options" :do you mean that using a PFont would be better?
3k -> 3kilo -> 3 thousand; 3 thousand words full of characters. I modified your code to know what is happening. I add a constrain method so the limits are set. Just saying, not tested/tried, maybe setting this string to pdf, on a class, and translating it as an image can be an option. https://processing.org/reference/libraries/pdf/ <- The last part GoToLoop last two points are other options to try.
Thanks Infsys,
But the only thing I see is that you constrained the offset. That doesn't change anything about the performance...
Putting the textesize, textalign or textfont in the setup (if we don't want to change them) makes it run hardly faster, the difference is scarce.
Well, I think we can conclude that displaying text in Android mode consumes a lot of CPU if we don't want to create a bitmap or Pgraphics. What else?
If you know Java, make this in Android Studio or Eclipse and try it there. You can import a processing project from there. I improve the code but in the instance you touch the screen the frame rate falls.
That's very smart infsys, I'm gonna try it!