【发布时间】:2011-03-14 18:53:11
【问题描述】:
当我调试以下代码时,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);
【问题讨论】:
-
[[CCDirector sharedDirector] winSize] 和 birdHeight 的值是多少?
-
在调试器中找不到。现在没事了。我使用clang调试和分析,结果birdsAlone是nil,node是垃圾......我使用[CCArray arrayWithCapacity:20]而不是[[CCArray alloc] initWithCapacity],输入太快^_^
-
你好,你是在“debug”还是“release”模式下调试?您不应该得到birdsAlone == nil ...另外,请指定放置这段代码的函数。birdsAlone 是类成员吗?输入参数?
-
我在调试模式下调试它。我不认为这是代码的问题。 BirdAlone 是一组鸟类(因为在这个游戏模式中,没有鱼。)
标签: iphone objective-c xcode cocos2d-iphone