September 2016
Beginner to intermediate
1089 pages
23h 8m
English
The first way we are going to implement detection is through the intersection of rectangles, which is also the simplest method.
We will use the bounding rectangle of the ScreenGameObject and check if it intersects with the bounding rectangle of the other ScreenGameObject.
The bounding rectangle changes each time we update the position of the sprite and, since we may be required to check with many other objects, it is best if we recalculate it after onUpdate. We are going to make a new method called onPostUpdate and do that inside it.
We have to add a new method to ScreenGameObject.
public void onPostUpdate(GameEngine gameEngine) {
mBoundingRect.set(
(int) mX,
(int) mY,
(int) mX + mWidth,
(int) mY + mHeight);
}If you need to override ...
Read now
Unlock full access