Skip to content

Commit

Permalink
Fixed the reset of the game when all blocks are removed.
Browse files Browse the repository at this point in the history
  • Loading branch information
dasdom committed Jan 22, 2015
1 parent 728eae7 commit dfe2a7f
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions PullToRefreshDemo/BreakOutToRefreshView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,7 @@ class BreakOutScene: SKScene, SKPhysicsContactDelegate {
let ball = SKSpriteNode(color: ballColor, size: CGSize(width: 8, height: 8))


ball.position = CGPoint(x: frame.size.width - 30.0 - ball.size.width, y: CGRectGetHeight(frame)*CGFloat(arc4random())/CGFloat(UINT32_MAX)
)
ball.position = CGPoint(x: frame.size.width - 30.0 - ball.size.width, y: CGRectGetHeight(frame)*CGFloat(arc4random())/CGFloat(UINT32_MAX))
ball.name = ballName

ball.physicsBody = SKPhysicsBody(circleOfRadius: ceil(ball.size.width/2.0))
Expand All @@ -309,6 +308,11 @@ class BreakOutScene: SKScene, SKPhysicsContactDelegate {
addChild(ball)
}

func removeBall() {
let ball = childNodeWithName(ballName)
ball?.removeFromParent()
}

func createLoadingLabelNode() {
let loadingLabelNode = SKLabelNode(text: "Loading...")
loadingLabelNode.fontColor = UIColor.lightGrayColor()
Expand All @@ -319,6 +323,12 @@ class BreakOutScene: SKScene, SKPhysicsContactDelegate {
addChild(loadingLabelNode)
}

func reset() {
createBlocks()
removeBall()
createBall()
}

func start() {
isStarted = true

Expand Down Expand Up @@ -379,7 +389,8 @@ class BreakOutScene: SKScene, SKPhysicsContactDelegate {
if otherBody != nil && (otherBody!.categoryBitMask & blockCategory != 0) {
otherBody!.node?.removeFromParent()
if isGameWon() {
createBlocks()
reset()
start()
}
return
}
Expand Down

0 comments on commit dfe2a7f

Please sign in to comment.