Wednesday, 11 September 2013

Behavior Star Collecting Algorithm changes

Behavior Star Collecting Algorithm changes

I have made simple algorithm for collecting stars.In which, i calculate
the CGRect for my physics ball and CGrect for stars. Then i check whether
my CGRect of ball intersect the CGRect of any star. If it intersect then i
do respective work to it. I have used platform in my game on which Ball
can move.Code for collecting stars is:
CGRect Ball =
CGRectMake((node->innerCircleBody->GetPosition().x*PTM_RATIO)-15,(node->innerCircleBody->GetPosition().y*PTM_RATIO)-15,30,
30);
for (int i =0 ; i < [starsArray count]; i++) {
CCSprite *starSprite = [starsArray objectAtIndex:i];
CGRect targetRect = CGRectMake(starSprite.position.x -
(starSprite.contentSize.width/2),starSprite.position.y -
(starSprite.contentSize.height/2),
starSprite.contentSize.width,starSprite.contentSize.height);
if(CGRectIntersectsRect(Ball,targetRect)||CGRectContainsRect(Ball,
targetRect)){
//doing respective work for star collection.
}
}
Now, when i give permission to ball to pass through the platforms at that
time when ball passing from stars , it is not giving collision(that is
cgrectintercect). I am stuck on this issue since 2 days. I am not getting
wny this happening. when Ball moves down side i, that is if it has
vertical velocity at that time i am not getting collision detaction
between ball and stars using the method described above.

No comments:

Post a Comment