Is it possible to detect collisions with certain parts of a sprite's bounding box? For example if a sprite jumps and landed into a platform, the bottom part of the sprite bounding box's and the top part of the platform bounding box's collision will be detected.
Asked
Active
Viewed 157 times
1 Answers
0
In my projects I have a helper library that has lots of little functions including something like:
CCRect CHelperMethods::InsetRect(const CCRect rectToInset, const float insetValueX, const float insetValueY) {
return CCRectMake(rectToInset.origin.x + insetValueY, rectToInset.origin.y + insetValueY, rectToInset.size.width - insetValueX * 2, rectToInset.size.height - insetValueY * 2);
}
Then, for example with a sprite that has landed, it would have a State variable, and I would say (psuedo code)
if(sprite.getState() == constStateLanded) {
CheckCollisionForBox( CHelperMethods::InsetRect(sprite->boundingBox(), yourXOffset, yourYOffset));
}
HTH, as you tagged Android and ipHone I didn't know whether you wanted Obj-C or C++ :)

user1474142
- 124
- 1
- 6
-
I tagged Android only and java for the language but thanks for your help! I'll try to use your suggestion. :) – user3194348 Jan 15 '14 at 07:43
-
Ah, I guess the other edit added the tags :). SAme thing applies in Java, though – user1474142 Jan 16 '14 at 06:17