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.
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)
.