2013-02-27 108 views
0

我是新來的Cocos2D所以請幫助我,如果ü可以設定精靈使用後臺位置

我有背景從右向左移動,背景中包含小窗口3行窗口

_spaceDust1 = [CCSprite spriteWithFile:@"bg_front_spacedust.png"]; 
_spaceDust2 = [CCSprite spriteWithFile:@"bg_front_spacedust.png"]; 

    CGPoint dustSpeed = ccp(0.1 , 0.1); 
    CGPoint bgSpeed = ccp(0.05 , 0.05); 

    [_backgroundNode addChild:_spaceDust1 z:0 parallaxRatio:dustSpeed positionOffset:ccp(0,winSize.height/2)]; 
    [_backgroundNode addChild:_spaceDust2 z:0 parallaxRatio:dustSpeed positionOffset:ccp(_spaceDust1.contentSize.width , winSize.height/2)]; 

現在添加敵人至極也從右邊移到左邊以相同的速度

 _robbers = [[CCArray alloc] initWithCapacity:kNumAstroids]; 
    for (int i = 0; i < kNumAstroids; ++i) { 
     CCSprite *asteroid = [CCSprite spriteWithSpriteFrameName:@"robber.png"]; 
     asteroid.visible = NO; 
     [_batchNode addChild:asteroid]; 
     [_robbers addObject:asteroid]; 
    } 

在更新方法

 double curTime = CACurrentMediaTime(); 
    if (curTime > _nextRunemanSpawn) { 
    float randSecs = [self randomValueBetween:0.20 andValue:1.0]; 
    _nextRunemanSpawn = randSecs + curTime; 

    float randY = 80.0; 
    float randY1 = 185.0; 
    float randY2 = 293.0; 
    float randDuration = [self randomValueBetween:5.2 andValue:5.2]; 
    float randDuration1 = [self randomValueBetween:1.0 andValue:1.0]; 

    CCSprite *asteroid = [_robbers objectAtIndex:_nextRobber]; 
    _nextRobber++; 

    if (_nextRobber >= _robbers.count) { 
     _nextRobber = 0; 
    } 
    //[asteroid stopAllActions]; 
    int winChoice = arc4random() % 3; 
    if (winChoice == 0) { 
     asteroid.position = ccp(winSize.width +asteroid.contentSize.width/2 , randY); 
     asteroid.visible = YES; 

    } 
    else if(winChoice == 1){ 

     asteroid.position = ccp(winSize.width +asteroid.contentSize.width/2 , randY1); 
     asteroid.visible = YES; 

    }else { 
     asteroid.position = ccp(winSize.width +asteroid.contentSize.width/2 , randY2); 
     asteroid.visible = YES; 

    } 



    [asteroid runAction:[CCSequence actions:[CCMoveBy actionWithDuration:randDuration position:ccp(-winSize.width-asteroid.contentSize.width, 0)], 
         [CCCallFuncN actionWithTarget:self selector:@selector(setInvisible:)],nil]]; 

一切進行得很順利,但我希望在一個窗口和任意位置設置此敵人
所以,我怎麼可以設置敵人的X參數,所以它可以被修復爲背景的窗口?

回答

0

出於某種原因,我不能評論,所以這是寫作答案。你究竟想要做什麼?我有點困惑。這聽起來像是你想要設置X位置,使其處於3個隨機位置之一,這是否正確?