开发者

Creating 2D Bounding Box's

开发者 https://www.devze.com 2023-03-17 11:00 出处:网络
how would I create a bounding box a开发者_Python百科round a object if I am using the canvas surfaceview? Would I have to do it in the object class? Inside of my view class? Any help is highly apprecia

how would I create a bounding box a开发者_Python百科round a object if I am using the canvas surfaceview? Would I have to do it in the object class? Inside of my view class? Any help is highly appreciated. Thanks in advance.


You could do it inside your view class, you could have a Rect instance called boundingBox or somthing, then have a meathod called checkBounds(int x, int y) that returns a boolean, then inside the checkBounds meathod just do:

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
}

so that way the meathod can be called from a bunch of different places.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号