创建2D边界框

时间:2011-07-04 23:28:37

标签: java android

如果我使用画布表面视图,如何在对象周围创建边界框?我是否必须在对象类中执行此操作?在我的视图类里面?任何帮助都非常感谢。提前谢谢。

1 个答案:

答案 0 :(得分:0)

你可以在你的视图类中做到这一点,你可以有一个名为boundingBox或somthing的Rect实例,然后有一个名为checkBounds(int x,int y)的meathod返回一个布尔值,然后在checkBounds meathod里面做:< / p>

if(boundingBox.contains(x,y))
{
    //put code here that moves a character or somthing
}else{
    //put code here that says a character cannot move or somthing
}

这样就可以从一堆不同的地方调用meathod。