加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iphone – cocos2d位置坐标

发布时间:2020-12-14 17:20:16 所属栏目:百科 来源:网络整理
导读:当我调试以下代码时,xPos = 0,yPos = 0,很奇怪 CCNode* node = [birdsAlone objectAtIndex:nextInactiveBird];NSAssert([node isKindOfClass:[BirdEntity class]],@"not a bird entity");BirdEntity* bird = (BirdEntity*) node;float birdHeight = CGRectGe
当我调试以下代码时,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会导致结果为零.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读