0
我每秒都會向場景中添加敵人,我需要描述主角穿過這些敵人的透明物體之間的特定距離,這裏是我的代碼敵人的情景:SpriteKit - 如何在我的遊戲中添加具有特定距離的對象
- (void)createEnemy {
int GoOrNot = [self getRandomNumberBetween:0 to:1];
if(GoOrNot == 1){
int randomEnemy = [self getRandomNumberBetween:0 to:1];
if(randomEnemy == 0)
enemy = [[SKSpriteNode alloc]initWithImageNamed:@"car.png"];
else
enemy = [[SKSpriteNode alloc]initWithImageNamed:@"block.png"];
int xPostion = [self placeRandomObject] ;
int yPostion = 1150;
enemy.position = CGPointMake(xPostion, yPostion);
enemy.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:enemy.size];
enemy.name = @"enemy";
enemy.physicsBody.categoryBitMask = enemyCategory;
enemy.physicsBody.contactTestBitMask = carCategory;
enemy.physicsBody.collisionBitMask = 0;
enemy.physicsBody.dynamic = YES;
enemy.physicsBody.usesPreciseCollisionDetection = YES;
[self addChild:enemy];
SKAction *wait = [SKAction waitForDuration:.20];
SKAction *move = [SKAction moveToY:self.scene.frame.origin.y-10 duration:enemySpeed];
SKAction *remove = [SKAction removeFromParent];
SKAction *runAction = [SKAction sequence:@[wait,move , remove]];
[enemy runAction:[SKAction repeatActionForever:runAction]];
}
}
加入敵人:
- (void)addEnemies {
SKAction *wait = [SKAction waitForDuration:.55];
SKAction *callEnemies = [SKAction runBlock:^{ [self createEnemy];}];
updateEnimies = [SKAction sequence:@[wait,callEnemies]];
[self runAction:[SKAction repeatActionForever:updateEnimies] withKey:@"addEnemy"];
}
似乎它的工作!謝謝 –