0

初めてのiOSアプリを作っていますが、問題があります... 動いているオブジェクトが画面の上から下に来ます。ゲームの目的は、動くオブジェクト (位置はランダムです) が画面から出る前に殺すことです。オブジェクトが出てきたら、3 つのライフのうちの 1 つを失います。私はそのようにします:

if(movingObject.position.y < 0)
    _lives--;

しかし、アプリを起動して画面からオブジェクトが出てくると、すぐに 3 つのライフを失ってしまいます...

オブジェクトを動かすことで最大 1 人のライフを失うにはどうすればよいですか?

新しいmovingObjectを作成するコードは次のとおりです

double curTime = CACurrentMediaTime();
if (curTime > _nextMovingObjectSpawn)
{
    float randSecs = [self randomValueBetween:3 andValue:5];
    _nextMovingObjectSpawn = randSecs + curTime;

    float randX = [self randomValueBetween:25 andValue:winSize.width/2-20];
    float randDuration = [self randomValueBetween:4 andValue:6];

    CCSprite *movingObject = [_movingObjects objectAtIndex:_nextMovingObject];
    _nextMovingObject++;
    if (_nextMovingObject >= _movingObjects.count) _nextMovingObject = 0;

    [movingObject stopAllActions];
    movingObject.position = ccp(randX, winSize.height+movingObject.contentSize.height/2);
    movingObject.visible = YES;
    [movingObject runAction:[CCSequence actions: [CCMoveBy actionWithDuration:randDuration position:ccp(0, -winSize.height-movingObject.contentSize.height)], [CCCallFuncN actionWithTarget:self selector:@selector(setInvisible:)], nil]];
}

ありがとうございました!:)

4

1 に答える 1