In my game, once an object contacts with the ground, the game is over. So, once that happens, I made an animation which is pretty much two red flashes on the background when the object hits the ground. That animation doesn't happen anymore and I'm confused to why. I had recently added scene transition right after my animation code, but it doesn't run the animation and just transitions to new scene. Can you please help me determine to what I'm doing wrong? The scene class (a new swift file I created):
My GameScene didBeginContact code:
Code:
classGameOverNew:SKScene{
var score =NSInteger()
override func didMoveToView(view:SKView){
backgroundColor =SKColor.redColor()
var scoreTextNode =SKLabelNode(fontNamed:"Copperplate")
scoreTextNode.text ="SCORE : \(score)"
scoreTextNode.horizontalAlignmentMode =SKLabelHorizontalAlignmentMode.Center
scoreTextNode.verticalAlignmentMode =SKLabelVerticalAlignmentMode.Center
scoreTextNode.fontSize =20
scoreTextNode.fontColor =SKColor.whiteColor()
scoreTextNode.position =CGPointMake(size.width /2.0, size.height /2.0)
addChild(scoreTextNode)
}
}
My GameScene didBeginContact code:
Code:
func didBeginContact(contact: SKPhysicsContact) {
if( moving.speed > 0 ) {
if( ( contact.bodyA.categoryBitMask & scoreCategory ) == scoreCategory || ( contact.bodyB.categoryBitMask & scoreCategory ) == scoreCategory ) {
score++;
scoreLabelNode.text = "\(score)"
} else {
moving.speed = 0;
object.physicsBody!.collisionBitMask = worldCategory
self.removeActionForKey("flash")
var turnBackgroundRed = SKAction.runBlock({() in self.setBackgroundColorRed()})
var wait = SKAction.waitForDuration(0.05)
var turnBackgroundWhite = SKAction.runBlock({() in self.setBackgroundColorWhite()})
var turnBackgroundSky = SKAction.runBlock({() in self.setBackgroundColorSky()})
var sequenceOfActions = SKAction.sequence([turnBackgroundRed,wait,turnBackgroundWhite,wait, turnBackgroundSky])
var repeatSequence = SKAction.repeatAction(sequenceOfActions, count: 2)
var canRestartAction = SKAction.runBlock({() in self.letItRestart()})
var groupOfActions = SKAction.group([repeatSequence, canRestartAction])
self.runAction(groupOfActions, withKey: "flash")
// this is the scene transition code I added
let myScene = GameOverNew(size: self.size)
myScene.scaleMode = scaleMode
let reveal = SKTransition.fadeWithDuration(2.0)
self.view?.presentScene(myScene, transition: reveal)
}
}
}
Last edited: