Reputation: 1
Please help me to increase the speed of node in swift. I am using spritekit. I am designing one screen 2d game. in my game, there is one obstacle to defend a node from balls. player controls the obstacle with swiping. and there are 4 more balls moving randomly on the screen. I need to increase speed of balls every 10 points but i couldn't do that. please help me i am new on swift and spritekit.
here is a little part of my code
override init(size: CGSize)
{
super.init(size: size)
ball1.physicsBody?.applyImpulse(CGVectorMake(CGFloat(ballSpeed), CGFloat(ballSpeed)))
ball2.physicsBody?.applyImpulse(CGVectorMake(CGFloat(ballSpeed), CGFloat(ballSpeed)))
ball3.physicsBody?.applyImpulse(CGVectorMake(CGFloat(ballSpeed), CGFloat(ballSpeed)))
ball4.physicsBody?.applyImpulse(CGVectorMake(CGFloat(ballSpeed), CGFloat(ballSpeed)))
}
I cant change the value of ballSpeed variable after the game has started.
Upvotes: 0
Views: 671
Reputation: 903
I assume you have a score variable. You can let a function check the score and add to the ballSpeed
every 10 points. This can either be done inside of the update function
or with an SKAction
that checks every period of time.
if self.score % 10 == 0 {
self.ballSpeed++
}
This will increase your ballSpeed
by one every ten points.
Upvotes: 1