简体   繁体   中英

Creating 2D Bounding Box's

how would I create a bounding box around 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM