0

検索にうんざりしていて、cocos 2dが初めてなので、私を助けてください。addRed をスケジュールし、すべてのスプライトを画面内でランダムに移動させたい場合、最後のスプライトが移動するだけです。どんな助けでも感謝し、前もって感謝します。

-(void)addRed 
{
redSprite = [CCSprite spriteWithImageNamed:@"Red.png"];;
CGSize screenSize = [[CCDirector sharedDirector] viewSize];
[redSprite setPosition:CGPointMake(screenSize.width/2, screenSize.height/2)];
[self resizeSprite:redSprite toWidth:80 toHeight:80];
[self addChild:redSprite z:10];

[self gameStart];
}

- (void)gameStart {
    // Create the actions
CGSize result = [[UIScreen mainScreen] bounds].size;
CGPoint nextPoint;

if (redSprite.position.x == result.width-40.0) {
    nextPoint.x = redSprite.position.x - kAccelXAxis;
    backx = YES;
}
else {
    if (redSprite.position.x == 40.0) {
        nextPoint.x = redSprite.position.x + kAccelXAxis;
        backx = NO;

    }
    else {
        if (backx) {

            nextPoint.x = redSprite.position.x - kAccelXAxis;
        }
        else
        {
            nextPoint.x = redSprite.position.x + kAccelXAxis;
        }
    }
}

if (redSprite.position.y == 40.0) {
    nextPoint.y = redSprite.position.y + kAccelYAxis;
    backy = YES;

}
else {
    if (redSprite.position.y == result.height-40.0) {
        nextPoint.y = redSprite.position.y - kAccelYAxis;
        backy = NO;

    }
    else {
        if (backy) {
            nextPoint.y = redSprite.position.y + kAccelYAxis;
        }
        else
        {
            nextPoint.y = redSprite.position.y - kAccelYAxis;
        }
    }
}

    CCAction *myAction = [CCActionSequence actions:[CCActionMoveTo actionWithDuration:0.01 position:nextPoint], [CCActionCallFunc actionWithTarget:self selector:@selector(gameStart)], [CCActionCallFunc actionWithTarget:self selector:@selector(updateCol:)],nil];
[myAction setTag:10];

[redSprite runAction:myAction];

}
4

1 に答える 1