How to process a lot of drawings

I am developing a game where I use a lot of drawings. The drawable directory holds more than 10 MB of memory (about 900 outputs). At the beginning of each game level, I load an array of drawings with only the necessary drawings, so when I draw them, I mean only certain drawings. This will reduce the number of my drawings to 300, but there are times when then only 900 drawings can be used. Although, when I read the drawings, they use more than 40-50 MB of memory. I tried to load them during the game, but it was useless because the game slows down incredibly.

Ok I forgot to add the code: P My game is based on LunarLancher, so the code is nothing new for you.

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< 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 ]; } 

This code is just a sample that I wrote right now, but I have the same idea.

it

 LoadPixmap(context); 

the method is also called when I update all the variables, so I have a chance to add / remove some drawings that I will need to use.

and this part of the code

 if ( IsPixmapNeeded(m_Objects[iIndex]) ) 

prohibit the loading of drawings that are located right now in the m_Pixmap array.

My question is how to handle a lot of drawings correctly? My problem is not the problem of my code, I would rather find the best way to handle a lot of drawings.

+4
source share
1 answer

Do you use a factory bitmap to download these bitmaps anywhere?

If yes,

Make sure you consider BitMap.recycle ();

Also, make sure that there is enough VM budget for each phone to allocate memory for these images.

If you are not using bitmapfactory, then kk.

0
source

Source: https://habr.com/ru/post/1385230/


All Articles