iphone – cocos2d位置坐标

前端之家收集整理的这篇文章主要介绍了iphone – cocos2d位置坐标前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
当我调试以下代码时,xPos = 0,yPos = 0,很奇怪

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);

解决方法

如果你得到0,你不期望它们,两个常见的原因是:

>整数舍入.例如,如果你做int x = 3 * .25,x将为0.我不认为这是你的问题.>你的链中的一个对象是零.请记住,在Cocoa中,[nil anySelector]是有效的 – 它不会像你期望的那样与nil对象一起崩溃. [nil intValue](或floatValue等)== 0.所以如果你有[[myObject someProperty] someOtherProperty],那么沿途的任何东西都是0会导致结果为零.

猜你在找的Xcode相关文章