Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/198.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何获取两个对象的碰撞详细信息_Android_Bitmap_Android Canvas_Collision Detection - Fatal编程技术网

Android 如何获取两个对象的碰撞详细信息

Android 如何获取两个对象的碰撞详细信息,android,bitmap,android-canvas,collision-detection,Android,Bitmap,Android Canvas,Collision Detection,我正在开发一个游戏,其中我有两个对象:1>平面和2>云。 我知道当它们碰撞时会发生什么 我尝试过以下两种方法,但都无济于事:- (一) (二) 我已经在不同的类中使用位图初始化了平面和云,getY()和getX()方法以int返回坐标 平面对象:- 平面=新平面(BitmapFactory.decodeResource(getResources(),R.drawable.plane),250700) 云对象也是相同的 有人请帮忙。您必须在特定条件下使用范围。移动对象的速度可能不是1。 所以在这种

我正在开发一个游戏,其中我有两个对象:1>平面和2>云。 我知道当它们碰撞时会发生什么

我尝试过以下两种方法,但都无济于事:- (一)

(二)

我已经在不同的类中使用位图初始化了平面和云,getY()和getX()方法以int返回坐标

平面对象:- 平面=新平面(BitmapFactory.decodeResource(getResources(),R.drawable.plane),250700)

云对象也是相同的


有人请帮忙。

您必须在特定条件下使用范围。移动对象的速度可能不是1。 所以在这种情况下,这个条件永远不会满足

suppose you have 2 objects then source and dest then condition will be as below:
// use below condition for x
if(source.x >=dest.x && source.x<=(dest.x+dest.width))
// use below condition for y
if(source.y >=dest.y && source.x<=(dest.y+dest.height))

This both conditions are required to check collision.
假设您有两个对象,那么source和dest的条件如下:
//对x使用以下条件

如果(source.x>=dest.x&&source.x=dest.y&&source.x获取两个对象的中心,然后根据半径或直径检测碰撞!请提供有关您正在使用的对象的更多详细信息,以及为什么您提到的那些方法不能满足您的要求?我也尝试过,但如果您能向我展示一些代码场景,则无法实现
if(((cloud.getY() + cloud.getBitmap().getHeight() / 2)==(plane.getY() + plane.getBitmap().getHeight() / 2))&&((cloud.getX() - cloud.getBitmap().getWidth() / 2)==(plane.getX() - plane.getBitmap().getWidth() / 2)))
        {
            plane.reset();
        }
suppose you have 2 objects then source and dest then condition will be as below:
// use below condition for x
if(source.x >=dest.x && source.x<=(dest.x+dest.width))
// use below condition for y
if(source.y >=dest.y && source.x<=(dest.y+dest.height))

This both conditions are required to check collision.