我尝试开发一个具有球位图和方形位图的游戏应用程序。方形位图从下向上滚动,球从上到下下降。
我想写一个代码来碰撞两个位图(球和方形)
任何人都可以帮助我..
private void doDraw(Canvas c) {
/* int width = c.getWidth();
int height = c.getHeight();
c.drawRect(0, 0, width, height, backgroundPaint); */
Bitmap ball = BitmapFactory.decodeResource(getResources(),R.drawable.ball); //Load a ball image.
ballH=ball.getHeight();
ballW=ball.getWidth();
Bitmap kangoo = BitmapFactory.decodeResource(getResources(),R.drawable.b);
sh=kangoo.getHeight();
sw=(kangoo.getWidth());
ballX = (int) (mScrWidth /2) - (ballW / 2) ; //Centre ball X into the centre of the screen.
ballY = -50; //Centre ball height above the screen.
c.drawColor(Color.WHITE);
c.drawBitmap(kangoo,-10,vall - ,null); c.drawBitmap(kangoo,(sw),vall - ,null);
synchronized (model.LOCK) {
ballX = model.ballPixelX;
ballY = model.ballPixelY;
}
//c.drawBitmap(ball, ballX,ballY, ballPaint);
c.drawBitmap(kangoo,-10, vall2--, null);
c.drawBitmap(kangoo,(sw), vall2--, null);
c.drawBitmap(kangoo,-10, vall3--, null);
c.drawBitmap(kangoo, (sw), vall3--, null);
}
这是我的代码.. 除碰撞外,一切都完美无缺。 这两个物体只是交叉..