我是新來的,所以我希望你能幫助我。平臺上的怪物/敵人(如Doodlejump)Cocos2d
我在製作簡單的cocos2d遊戲
我實現了它在另一場比賽一個跳一個像塗鴉跳躍下面的教程。
在上述教程中,怪物/目標自由地從屏幕右側移動到左側。當我在我的應用程序上實現它時,怪物就像從左到右飛行。如果我想讓怪物像塗鴉跳躍一樣站在平臺上呢?我會做什麼特別的事情?
PS:我嘗試了谷歌其他一些事情,但沒有工作
這裏是怪物/目標代碼:
- (void)initPlatforms {
// NSLog(@"initPlatforms");
currentPlatformTag = kPlatformsStartTag;
while(currentPlatformTag < kPlatformsStartTag + kNumPlatforms) {
[self initPlatform];
currentPlatformTag++;
}
[self resetPlatforms];
}
- (void)initPlatform {
CGRect rect;
switch(random()%2) {
case 0: rect = CGRectMake(608,64,102,36); break;
case 1: rect = CGRectMake(608,128,90,32); break;
}
AtlasSpriteManager *spriteManager = (AtlasSpriteManager*)[self getChildByTag:kSpriteManager];
AtlasSprite *platform = [AtlasSprite spriteWithRect:rect spriteManager:spriteManager];
[spriteManager addChild:platform z:3 tag:currentPlatformTag];
}
-(void)addTarget {
Sprite *target = [Sprite spriteWithFile:@"komodo.png"];
target.position = ccp(300,200);
[self addChild:target];
CGSize winSize = [[Director sharedDirector]winSize];
int minX = target.contentSize.height/2;
int maxX = winSize.height -target.contentSize.height/2;
int rangeX = maxX - minX;
int actualX = (arc4random() % rangeX) +minX;
int minDuration = 2.0;
int maxDuration = 4.0;
int rangeDuration = maxDuration - minDuration;
int actualDuration = (arc4random() % rangeDuration) + minDuration;
id actionMove = [MoveTo actionWithDuration:actualDuration position:ccp(-target.contentSize.width,actualX)];
id actionMoveDone = [CallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)];
[target runAction:[Sequence actions:actionMove, actionMoveDone,nil]];
target.tag = 1;
[_targets addObject:target];
}
感謝那些誰可以幫助...你是太讚了。
爲什麼投票下來? :( – TeT 2012-01-11 02:15:45