Note that there are some explanatory texts on larger screens.

plurals
  1. POj2me: using custom fonts(bitmap) performance
    text
    copied!<p><br /></p> <p>I want to use custom fonts in my j2me application. so I created a png file contains all needed glyph and an array of glyphs width and another for glyphs offset in PNG file.</p> <p>Now, I want to render a text in my app using above font within a gameCanvas class. but when I use the following code, rendering text in real device is very slow. </p> <p>Note: the text is coded(for some purposes) to bytes and stored in this.text variable. 242=[space],241=[\n] and 243=[\r].</p> <pre><code>int textIndex = 0; while(textIndex &lt; this.text.length) { int index = this.text[textIndex] &amp; 0xFF; if(index &gt; 243) { continue; } else if(index == 242) lineLeft += 3; else if(index == 241 || index == 243) { top += font.getHeight(); lineLeft = 0; continue; } else { lineLeft += widths[index]; if(lineLeft &lt;= getWidth()) lineLeft = 0; int left = starts[index]; int charWidth = widths[index]; try{ bg.drawRegion(font, left, 0, charWidth, font.getHeight(), 0, lineLeft, top, Graphics.LEFT|Graphics.TOP); }catch(Exception ee) { } } textIndex++; } </code></pre> <p>Can anyone help me to improve performance and speed in my code?</p> <p>At end sorry for my bad English and thanks in advanced.:)</p> <p>Edit: I changed line</p> <pre><code> bg.drawRegion(font, left, 0, charWidth, font.getHeight(), 0, lineLeft, top, Graphics.LEFT|Graphics.TOP); </code></pre> <p>To:</p> <pre><code>bg.clipRect(left, top, charWidth, font.getHeight()); bg.drawImage(font, lineLeft - left, top,0) bg.setClip(0, 0, getWidth(), getHeight()); </code></pre> <p>but there was no difference in speed!!</p> <p>any help please!!</p> <hr> <p>Can anyone plz help me to improve my app?</p> <p>text will appear after 2-3 seconds in real device by this code, I want reduce this time to milliseconds. this is very important for me.</p> <p>Can I use threads? If yes, How?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload