Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to handle lots of drawables
    primarykey
    data
    text
    <p>I am developing a game, where I use lots of drawables. The "drawable" catalog hold over 10MB memory ( about 900 of drawables ). At the beggining of each game level I am loading the array of drawables only the necessary drawables, so when I am drawing them I only refer to certain drawables. This reduce the amount of my drawables to about 300, but there are some cases when then can be even 900 drawables that are used. Even though when I readed drawables they use over 40 - 50MB of memory. I was trying to load them them during the game but this was useless, because the game slows incredible.</p> <p>Ok. I forgot to add some code :P My game is base on LunarLancher, so code is nothing new for you.</p> <pre><code>class GraphicView extends SurfaceView implements SurfaceHolder.Callback { class GraphicThread extends Thread { public GraphicThread(SurfaceHolder surfaceHolder, Context context, Handlerhandler ) { ... LoadPixmap(context); ... } private void doDraw(Canvas canvas) { m_Pixmap[iIndex].setBounds( m_iX, m_iY, m_iX + WIDTH_I, m_iY + HEIGHT_I ); m_Pixmap[iIndex].draw( canvas ); } } private void LoadPixmap( Context context ) { int iID = 0; Resources res = context.getResources(); for( int iIndex=0; iIndex&lt; m_Objects.size(); ++iIndex ) { if ( IsPixmapNeeded(m_Objects[iIndex]) ) { continue; } iID = res.getIdentifier("pixmap"+i, "drawable", "com.my.package"); if ( iID != 0 ) { m_Pixmap[iIndex] = context.getResources().getDrawable(iID); m_Pixmap[iIndex] = new ScaleDrawable( m_Pixmap[iIndex], 0, WIDTH_I, HEIGHT_I).getDrawable(); } } res = null; context = null; } m_Pixmap[] = new Drawable[ FRAMES ]; } </code></pre> <p>This code is only a sample that I have written right now, but I the idea is the same.</p> <p>This </p> <pre><code>LoadPixmap(context); </code></pre> <p>method is called also when I update all variables, so I have chance to add/remove some drawable that I will need to use.</p> <p>and this part of code</p> <pre><code>if ( IsPixmapNeeded(m_Objects[iIndex]) ) </code></pre> <p>prevent me to loading drawables that are right now in m_Pixmap array.</p> <p>My question, what is the right way to handle lots of drawables? My issue isn't the problem of my code, I rather would like to find some better way to handling lots of drawables. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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