I am making a 2D game with Sprite Kit and I need to add a method to speed up the game after every 50 points.
I worked out a method that adds the speed as wanted, bu
if you want to update the speed at regular intervals, you can use the modulus operator - take the remainder after dividing by your interval - if that equals zero, take action. The reason you find the game speeding up completely is that the next time through the update function, it's still on the right points level, and it just increments the speed - you could add another variable to track if you're ready for an increment
// as part of class declaration
var bReadyForIncrement : Bool = true
let pointIncrement : Int = 4 // or whatever you need
// inside the update method
// points are added when an enemy is destroyed
// pointSpeed is the float variable that is used to change positions
if (points % 4)
{
if bReadyForIncrement
{
pointSpeed++;
bReadyForIncrement = false // set this to true wherever you add points
}
}