2

I am an Android Newbie and I'm developing Go game application for android. I'm having a problem with drawing single stone on my board.
Here is my onDraw() method.

public void onDraw(Canvas canvas) {
   //drawing a board
   //...
   //...

     canvas.drawBitmap(stone_image, stoneX - (stone_image.getWidth() / 2), stoneY
     - (stone_image.getHeight() / 2),paint);
}

And I have an onTouch() method:

public boolean onTouchEvent(MotionEvent event) {
    stoneX = (int) event.getX();
    stoneY = (int) event.getY();
    return true;
}

The point is, when I set background color in my class constuctor using this method:

setBackgroundColor(Color.WHITE);

Application can't draw a stone on the board after a touchEvent, but when I don't set a background color, application draws a stone perfectly.
P.S. Attributes stoneX,stoneY are correctly defined and initialized.

Olivier Dulac
  • 3,695
  • 16
  • 31
Ricardo Simmus
  • 334
  • 4
  • 19

1 Answers1

2

I don't know what View you are using, but I know that there is some problems when using a SurfaceView with a background (could be the case for other views too?) where the background draws on top so you only get a background.

Instead of setting the background color with setBackgroundColor(Color.WHITE), you should start your onDraw() with canvas.drawColor(Color.WHITE).

Jave
  • 31,598
  • 14
  • 77
  • 90
  • I'm using a SurfaceView. Thanx your advice worked! P.S. What should I do, to set the background image? – Ricardo Simmus Jan 03 '12 at 09:51
  • You are welcome, remember to mark the question as answered :) To use a background image, you can replace the drawColor with a drawBitmap and draw an image that way, or if you have a drawable, you would call it's draw() from your onDraw. – Jave Jan 03 '12 at 09:52