我是编程新手,但我设法创建了一个游戏,我跳过了Xcode中的障碍。问题是障碍物彼此之间的距离相同。任何人都可以帮我编写游戏代码,以便障碍每次都有一个随机的距离吗?
为我的障碍编码:
SKSpriteNode *obstacle = [SKSpriteNode spriteNodeWithColor:[self getRandomColor] size:CGSizeMake(40, 50)];
obstacle.name = @"obstacle";
obstacle.position = CGPointMake(self.currentObstacleX, ground.position.y + ground.frame.size.height/2 + obstacle.frame.size.height/2);
obstacle.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:obstacle.size];
obstacle.physicsBody.categoryBitMask = obstacleCategory;
obstacle.physicsBody.dynamic = NO;
[self.world addChild:obstacle];
self.currentObstacleX += 250;