Copy link to clipboard
Copied
Hi,
this may have been ask several times, but what is the exact / best way to use custom fonts in an iOS app?
It seems, that by using a lot of textfields, the app is not running smooth anymore.
Is there some magic way that will restore performance? And still be able to use custom fonts?
kind regards!
The 'magic trick' would be to create bitmaps of the textfields and add these to the display list rather than the textfields.
//container is a sprite that has a textfield added to it.
var bmp:BitmapData = new BitmapData(container.width, container.height);
bmp.draw(container);
var snapshot:Bitmap = new Bitmap(bmp);
snapshot.smoothing = true;
snapshot.cacheAsBitmap = true;
addChild(snapshot);
Copy link to clipboard
Copied
The 'magic trick' would be to create bitmaps of the textfields and add these to the display list rather than the textfields.
//container is a sprite that has a textfield added to it.
var bmp:BitmapData = new BitmapData(container.width, container.height);
bmp.draw(container);
var snapshot:Bitmap = new Bitmap(bmp);
snapshot.smoothing = true;
snapshot.cacheAsBitmap = true;
addChild(snapshot);
Copy link to clipboard
Copied
Hi! Just realized that I didn't mark your answer, but that was indeed working! Kinda weard still, I thought using bitmap drawing would be much slower then just using "simple" ready made text field. Anyways...Thnx for the tip!
Copy link to clipboard
Copied
Very true... rendering TFs to bitmaps is faster than rendering TFs directly, even with cacheAsBitmap enabled on the text fields.
However, cacheAsBitmap helps prevent memory overruns in some cases, as there are hooks in Flash to garbage collect cached bitmaps early, when they are no longer needed (I believe: even setting visible to false on a TF with CAB will cause the bitmap to be garbage collected -- someone might correct me on that).
This more "active" garbage collection can make the difference sometimes, in GPU mode especially, if you are scolling lots of text fields. In one of my apps, scrolling many bitmaps (rendered TFs) would eventually cause a crash (memory overrun), while scrolling the TFs with CAB enabled was fine. I also had code to set visible to false on objects whose bounds were no longer within the visible stage area.
Note: in the code above, unless "snapshot" or a container thereof is scaled, there is no need to use cacheAsBitmap on a Bitmap (you'd be using twice as much memory for nothing).
Find more inspiration, events, and resources on the new Adobe Community
Explore Now