【发布时间】:2012-02-09 18:39:56
【问题描述】:
我是编程新手,我一直在用 cocos2d 做实验,问题出在这里,我做了一个简单的游戏,设备是纵向的,它有掉落的精灵,我希望精灵在顶部的位置消失sprite
这里有一些你可能感兴趣的代码:
这是下落的精灵,它从屏幕顶部落到底部
-(void)addRock {
CCSprite *rock = [CCSprite spriteWithFile:@"rock.png"
rect:CGRectMake(0, 0, 27, 40)];
// Determine where to spawn the target along the X axis
CGSize winSize = [[CCDirector sharedDirector] winSize];
int minX = rock.contentSize.width/2;
int maxX = winSize.width - rock.contentSize.width/2;
int rangeX = maxX - minX;
int actualX = (arc4random() % rangeX) + minX;
// Create the target slightly off-screen along the right edge,
// and along a random position along the X axis as calculated above
rock.position = ccp(actualX, 500);
[self addChild:rock];
// Determine speed of the target
int actualDuration = spriteDuration;//speed of sprite
// Create the actions
id actionMove = [CCMoveTo actionWithDuration:actualDuration position:ccp(actualX,-winSize.height+ rock.contentSize.height)];
id actionMoveDone = [CCCallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)];
[rock runAction:[CCSequence actions:actionMove, nil]];
}
当精灵移动完成时
-(void)spriteMoveFinished:(id)sender {
CCSprite *sprite = (CCSprite *)sender;
[self removeChild:sprite cleanup:YES];
}
【问题讨论】:
-
我相信你的 spriteMoveFinished 没有被调用?
-
还没有,如何让它与精灵代码相匹配?
-
好的,刚刚添加:id actionMoveDone = [CCCallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)];
-
那么你的 spriteMoveFinished 现在什么时候被调用了?
-
是的,它被调用了,我已将它添加到我上面的代码中。
标签: iphone objective-c ios5 cocos2d-iphone