I'm trying to build a simple game for the exercise sake and cannot figure out why the frame's border is not moving when everything else is.
When I reach the last pillar and move a bit to the right the game ends. This is somehow because the frames border does not move when the goat and pillars does.
I have three layers which is SKNode's. One called _mainLayer, second called _playerLayer and third called _squareLayer. _mainLayer contains _playerLayer and _squareLayer.
When I move the screen this code is being used:
-(void)moveScreen {
_xMoved += 100;
SKAction *move = [SKAction moveByX:-100 y:0 duration:0.5];
[_squareLayer runAction:move];
[_playerLayer runAction:move];
}
I have tried to use [_mainLayer runAction:move] instead of the two other calls but then the gameover screen is not moving along which is added in directly into the scene class (the "self").
_gameOverScreen = [[EndScene alloc] init];
_gameOverScreen.position = CGPointMake(self.size.width / 2, self.size.height / 2);
_gameOverScreen.gameOver.size = CGSizeMake(self.frame.size.width, _gameOverScreen.gameOver.size.height / 2);
[self addChild:_gameOverScreen];
The gameover screen is a SKNode class I made myself.
Does anyone have any suggestions?
I found a solution to my problem.
-(void)didSimulatePhysics {
// If the goat didn't get on top of a platform
[_playerLayer enumerateChildNodesWithName:@"Goat" usingBlock:^(SKNode *node, BOOL *stop) {
if (!CGRectContainsPoint(CGRectMake(_xMoved, 0, self.frame.size.width, self.frame.size.height), node.position)) {
_gameOverScreen.numberScore = _score;
[_gameOverScreen testNewScore:_score];
[_scoreLabel removeFromParent];
_gameOverScreen.hidden = NO;
_gameOver = YES;
}
}];
}
By making a new CGRect that simulates the screen moving I got it to work. But why this (the code below) won't work I don't know.
-(void)didSimulatePhysics {
// If the goat didn't get on top of a platform
[_playerLayer enumerateChildNodesWithName:@"Goat" usingBlock:^(SKNode *node, BOOL *stop) {
if (!CGRectContainsPoint(self.frame, node.position)) {
_gameOverScreen.numberScore = _score;
[_gameOverScreen testNewScore:_score];
[_scoreLabel removeFromParent];
_gameOverScreen.hidden = NO;
_gameOver = YES;
}
}];
}