gpt4 book ai didi

ios - 当 Sprite 到达该位置时代码崩溃

转载 作者:行者123 更新时间:2023-11-28 22:10:39 25 4
gpt4 key购买 nike

我使用下面的代码来随机显示云

- (void) cloudFly
{
int whichcloud = (arc4random() % 2) + 1;
CCSprite *target = [CCSprite spriteWithImageNamed:[NSString stringWithFormat:@"cloud%d.png",whichcloud]];
target.opacity = 0.3;

int minY = target.contentSize.height / 2;
int maxY = winSize.height - target.contentSize.height / 2;
int rangeY = maxY - minY;
int actualY = (arc4random() % rangeY) + minY;

target.position = ccp(winSize.width + (target.contentSize.width/2), actualY);
[self addChild:target];

int minDuration = 1.0;
int maxDuration = 3.0;
int rangeDuration = maxDuration - minDuration;
int actualDuration = (arc4random() % rangeDuration) + minDuration;

// Create the actions
id actionMove = [CCActionMoveTo actionWithDuration:actualDuration position:ccp(-target.contentSize.width / 2, actualY)];
id actionMoveDone = [CCActionCallFunc actionWithTarget:self selector:@selector(cloudFinished:)];
[target runAction:[CCActionSequence actions:actionMove, actionMoveDone, nil]];
[_clouds addObject:target];
}

- (void)cloudFinished:(id)sender
{
CCSprite *sprite = (CCSprite *)sender;
[sprite stopAllActions];
[self removeChild:sprite cleanup:YES];
}

但是当云飞到那个位置的时候,这段代码会在一行崩溃

- (void)cloudFinished:(id)sender

我用的是cocos2d-iphone v3.x,我尝试注释/删除所有代码

- (void)cloudFinished:(id)sender

但它仍然崩溃。 BWT,ccsprite 是否移除标签?

最佳答案

CCActionCallFunc 需要一个没有参数的选择器,您应该改用 CCActionCallBlock。 this answer 中有一个示例.

关于ios - 当 Sprite 到达该位置时代码崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23004680/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com