0
我需要一些幫助。 我正在開發一款遊戲,我有兩個問題。遊戲 快速的解釋:SpriteKit在持續時間爲空的位置添加節點
有三種不同的節點(鯊魚(播放器),水球和磚)
遊戲開始時有一個鯊魚,四水球和八層磚。
與水球鯊魚接觸,球員的收入點,水球消失,遊戲增加了一個水球在隨機位置,
當磚鯊魚鯊魚接觸死了,從屏幕上消失。
我的問題是;
第一:當我們打水球時,我們如何在空位添加水球。我如何確保新的水球將在不同的位置,然後磚和其他水球?
二:
我要等待幾秒鐘之前,我添加新的水球。我怎麼做?
這是我的代碼的一部分。
謝謝
-(void) addWaterBallTopLeft {
WaterBall *waterBall = [WaterBall waterBallAtPosition:CGPointMake
([Util randomWithMin:(self.frame.size.width/10) + self.waterBall.size.width max:self.frame.size.width/2-self.brickT.size.width],
[Util randomWithMin:(self.frame.size.height- (self.frame.size.height/4)) + self.brickW.size.height max:self.frame.size.height-20])];
waterBall.name = @"WATERBALLTL";
[self addChild:waterBall ];
}
-(void) addWaterBallTopRight {
WaterBall *waterBall = [WaterBall waterBallAtPosition:CGPointMake([Util randomWithMin:self.frame.size.width/2+20 max:self.frame.size.width-20], [Util randomWithMin:(self.frame.size.height- (self.frame.size.height/4)-20) max:self.frame.size.height-20])];
waterBall.name = @"WATERBALLTR";
[self addChild:waterBall ];
}
-(void) addWaterBallBottomLeft {
WaterBall *waterBall = [WaterBall waterBallAtPosition:CGPointMake([Util randomWithMin:20 max:self.frame.size.width/2-20], [Util randomWithMin:(self.frame.size.height/2)+20 max:(self.frame.size.height- (self.frame.size.height/4)-20)])];
waterBall.name = @"WATERBALLBL";
[self addChild:waterBall];
}
-(void) addWaterBallBottomRight {
WaterBall *waterBall = [WaterBall waterBallAtPosition:CGPointMake([Util randomWithMin:self.frame.size.width/2+20 max:self.frame.size.width-20], [Util randomWithMin:(self.frame.size.height/2)+20 max:(self.frame.size.height- (self.frame.size.height/4)-20)])];
waterBall.name = @"WATERBALLBR";
[self addChild:waterBall];
}
-(void) addBrick {
BrickW *brickW1 = [BrickW BrickWAtPosition:CGPointMake((self.frame.size.width/12)* 1 , self.frame.size.height - self.frame.size.height * 0.25) ];
[self addChild:brickW1];
BrickW *brickW2 = [BrickW BrickWAtPosition:CGPointMake((self.frame.size.width/12)* 3 , self.frame.size.height - self.frame.size.height * 0.25) ];
[self addChild:brickW2];
BrickW *brickW3 = [BrickW BrickWAtPosition:CGPointMake((self.frame.size.width/12)* 9, self.frame.size.height - self.frame.size.height * 0.25)];
[self addChild:brickW3];
BrickW *brickW4 = [BrickW BrickWAtPosition:CGPointMake((self.frame.size.width/12)* 11, self.frame.size.height - self.frame.size.height * 0.25)];
[self addChild:brickW4];
BrickT *brickT1 = [BrickT BrickTAtPosition:CGPointMake(self.frame.size.width/2 , (self.frame.size.height/24)*23)];
[self addChild:brickT1];
BrickT *brickT2 = [BrickT BrickTAtPosition:CGPointMake(self.frame.size.width/2 , (self.frame.size.height/24)*21) ];
[self addChild:brickT2];
BrickT *brickT3 = [BrickT BrickTAtPosition:CGPointMake(self.frame.size.width/2 , (self.frame.size.height/24)*13)];
[self addChild:brickT3];
BrickT *brickT4 = [BrickT BrickTAtPosition:CGPointMake(self.frame.size.width/2 , (self.frame.size.height/24)*15)];
[self addChild:brickT4];
}
- (void) didBeginContact:(SKPhysicsContact *)contact {
SKPhysicsBody *firstBody, *secondBody;
if (contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask) {
firstBody = contact.bodyA;
secondBody = contact.bodyB;
} else {
firstBody = contact.bodyB;
secondBody = contact.bodyA;
}
if (firstBody.categoryBitMask == CollisionCategoryBrick && secondBody.categoryBitMask == CollisionCategoryShark) {
NSLog(@"BRICK");
[contact.bodyB.node removeFromParent];
} else if (firstBody.categoryBitMask == CollisionCategoryWaterBall && secondBody.categoryBitMask == CollisionCategoryShark) {
NSLog(@"BALL");
self.addSeconds =YES;
[contact.bodyA.node removeFromParent];
[self addPoints:PointsPerHit];
if (![ self childNodeWithName:@"WATERBALLTL"]) {
[self addWaterBallTopLeft];
}
if (![ self childNodeWithName:@"WATERBALLTR"]) {
[self addWaterBallTopRight];
}
if (![ self childNodeWithName:@"WATERBALLBL"]) {
[self addWaterBallBottomLeft];
}
if (![ self childNodeWithName:@"WATERBALLBR"]) {
[self addWaterBallBottomRight];
} }
NSLog(@"%lu", (unsigned long)[self.children count]);
}
-(void)update:(CFTimeInterval)currentTime {
if (startGamePlay){
startTime = currentTime;
startGamePlay = NO;
}
timeSinceStart = (currentTime -startTime);
countDownInt = 1000 - (int)(currentTime-startTime);
if (countDownInt > 0 && self.addSeconds == NO) {
countDown.text = [NSString stringWithFormat:@"%i", countDownInt];
} else if(countDownInt > 0 && self.addSeconds == YES){
startTime +=2;
countDown.text = [NSString stringWithFormat:@"%i", countDownInt];
self.addSeconds = NO;
}
if (countDownInt == 0){
countDown.text [email protected]"0";
Level2 *level2 = [Level2 sceneWithSize:self.frame.size];
SKTransition *transition = [SKTransition fadeWithDuration:0.5];
[self.view presentScene:level2 transition:transition];
}
}
謝謝你,幫助 – dorcester 2014-10-05 22:37:56