我目前正在制作Flappy Bird副本。放松,它只是为了我和学习部分,我不会发布它,所以不要讨厌。
这只鸟被锁定在:
self.size.width/3
管道是这样生成的:
- (void)generatePipes {
for (NSInteger i = 0; i < 3; i++) {
pipeNode = [SKNode node];
[pipeNode setName:@"pipe"];
[pipeNode setPosition:CGPointMake(self.size.width + 100.0 + (200.0 * i), 0.0)];
[self addChild:pipeNode];
**BLABLABLA. Some code**
[pipeTop setPosition:CGPointMake(0.0, arc4random_uniform(250) + 460.0)];
[pipeBottom setPosition:CGPointMake(0.0, pipeTop.position.y - (550.0 + arc4random_uniform(10)))];
[pipeTop setPhysicsBody:[SKPhysicsBody bodyWithRectangleOfSize:pipeTop.size]];
[pipeBottom setPhysicsBody:[SKPhysicsBody bodyWithRectangleOfSize:pipeBottom.size]];
[pipeTop.physicsBody setDynamic:NO];
[pipeBottom.physicsBody setDynamic:NO];
pipeTop.physicsBody.categoryBitMask = blockBitMask;
pipeBottom.physicsBody.categoryBitMask = blockBitMask;
pipeNode.physicsBody.categoryBitMask = blockBitMask;
[pipeNode addChild:pipeTop];
//[pipeTop attachDebugRectWithSize:pipeTop.size];
//[pipeBottom attachDebugRectWithSize:pipeBottom.size];
[pipeNode addChild:pipeBottom];
}
}
这是我唯一做的一些工作,是的,我是游戏开发的新手。FirstDistance 是第一根管道到达之前的距离:
firstDistance += -moveAmount.x;
if(touchBegan > 0 && firstDistance > (self.size.width -(self.size.width/3)- 60)){
distanceSinceLastPipe += -moveAmount.x;
if (distanceSinceLastPipe >= 140.0) {
distanceSinceLastPipe = 0.0;
score += 1;
[_scoreLabel setText:[NSNumberFormatter localizedStringFromNumber:@(score)
numberStyle:NSNumberFormatterDecimalStyle]];
[self runAction:[SKAction playSoundFileNamed:@"pipe.mp3" waitForCompletion:NO]];
}
}
我如何告诉更新方法管道通过鸟最有效?计算管道之间的像素并重置它?或者有什么方法可以检测它们何时通过?