Reputation:
when i debug the following code, the xPos = 0, yPos = 0, weird
CCNode* node = [birdsAlone objectAtIndex:nextInactiveBird];
NSAssert([node isKindOfClass:[BirdEntity class]], @"not a bird entity");
BirdEntity* bird = (BirdEntity*) node;
float birdHeight = CGRectGetHeight([bird boundingBox]);
float xPos = ([[CCDirector sharedDirector] winSize].width - 100) * CCRANDOM_0_1() + 50;
float yPos = ([[CCDirector sharedDirector] winSize].height + birdHeight / 2.0f);
CGPoint location = ccp(xPos, yPos);
Upvotes: 4
Views: 713
Reputation: 24675
When you get 0s where you don't expect them, two common causes are:
Integer rounding. For example, if you do int x = 3 * .25, x will be 0. I don't think this is your problem.
One of the objects in your chain is nil. Remember, in Cocoa, [nil anySelector] is valid -- it doesn't crash with a nil object as you might expect. [nil intValue] (or floatValue, etc.) == 0. So if you have [[myObject someProperty] someOtherProperty], any of those things along the way being 0 will cause the result to be zero.
Upvotes: 1