how to "reset" canvas and bitmap ?

Problems with Canvas, OpenGL, etc...

how to "reset" canvas and bitmap ?

Postby freeaks » Wed Jul 07, 2010 11:58 am

My loadMap() method generate a canvas.throwIfRecycled exception when i try to load a new map.
When i start the game, the initial map loads and work fine though,
its only when i try to load a new map that i get the exception ..

how can i "reset" canvas and the bitmap i use to draw into, so i can startover fresh with them ?
here's what i use to create and draw my maps:
Code: Select all
picDest = Bitmap.createBitmap(width*tileSize, height*tileSize, Bitmap.Config.RGB_565);
canvas = new Canvas(picDest);
for (int y = 0; y < height; y++) {
  for (int x = 0; x < width; x++) {
    // process tile stuffs here ...
    /*
    col = ....:
    row = ....;
    */
    pic[x][y]= Bitmap.createBitmap(sheet, col*tileSize, row*tileSize, tileSize, tileSize);
    canvas.drawBitmap(pic[x][y],x*tileSize,y*tileSize,bitmPaint);
  }
}

so basicaly once i created and used picDest and canvas,
i cannot figure how to reset it all for when i want to load a new map..

tnx
freeaks
Freshman
Freshman
 
Posts: 6
Joined: Mon Jun 28, 2010 5:16 am

Top

Re: how to "reset" canvas and bitmap ?

Postby blundell » Wed Jul 07, 2010 1:32 pm

Canvas.clear(); or something?

Canvas.drawRect(0,0,sizeW,sizeH); overwrite whole screen with a blank color?

Haven't done any canvas stuff since J2ME so these are just guesses, but guesses in the right direction x
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: how to "reset" canvas and bitmap ?

Postby mark@project8games.com » Wed Jul 07, 2010 8:56 pm

First thing I would suggest is pulling your "picDest" and "canvas" objects from method scope into member scope. Initialize in the constructor and be done with it.

After that, it looks like you loadMap() method draws over the entire bitmap, so just call that method but without the additional initializations.
User avatar
mark@project8games.com
Developer
Developer
 
Posts: 41
Joined: Tue Mar 02, 2010 8:33 pm

Re: how to "reset" canvas and bitmap ?

Postby freeaks » Thu Jul 08, 2010 2:45 am

mark@project8games.com wrote:First thing I would suggest is pulling your "picDest" and "canvas" objects from method scope into member scope. Initialize in the constructor and be done with it.

After that, it looks like you loadMap() method draws over the entire bitmap, so just call that method but without the additional initializations.


thanks !
worked :)
freeaks
Freshman
Freshman
 
Posts: 6
Joined: Mon Jun 28, 2010 5:16 am

Top

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 6 guests