Cocos2d position coordinate

when I debug the following code, 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); 
+4
source share
1 answer

When you get 0s where you don't expect them, there are two common reasons:

  • Integer rounding. For example, if you execute int x = 3 * .25, x will be 0. I do not think this is your problem.

  • One of the objects in your chain is zero. Remember that in Cocoa [nil anySelector] is valid - it does not fall with a null object, as you might expect. [nil intValue] (or floatValue, etc.) == 0. So, if you have [[myObject someProperty] someOtherProperty], any of these things along the path is 0, will result in the result being zero.

+1
source

Source: https://habr.com/ru/post/1343663/


All Articles