Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Sharukh7

macrumors newbie
Original poster
Jul 7, 2015
7
0
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):

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:

xStep

macrumors 68020
Jan 28, 2003
2,031
143
Less lost in L.A.
What does the self.runAction code look like? Any animate with duration and completion block stuff in there? If so, try placing the transition code into the completion block.
 

Sharukh7

macrumors newbie
Original poster
Jul 7, 2015
7
0
What does the self.runAction code look like? Any animate with duration and completion block stuff in there? If so, try placing the transition code into the completion block.
I did figure out what code of line I need to use(same as you mentioned) and have been doing for past 1.5 days, but I'm getting different errors different times. I'm really new to this, so I can't get it right, since I'm not understanding all of its elements. I'm trying to run the whole else statement of didBeginContact method before animation occurs, but can't get it to work.
 

Sharukh7

macrumors newbie
Original poster
Jul 7, 2015
7
0
Sorry for not mentioning. I didn't realize that I was missing details. But, do you happen to know how I can make this function work? I will deeply appreciate it if you can help me with this. I'm trying to run the whole else code in didBeginContact method before a transition takes place. The way I putted my the transition code in else statement, it ignores the else part and just transitions. The line of code that I did figure out is:
Code:
func runAction(action: SKAction, withKey: String, callback: () -> Void) {
    // stuff runAction should do
    callback()
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.