Gabe12
Gabe12

Reputation: 627

Convert int to NSTimeInterval

I'm making a game in Swift and I want the sprites to move faster as the time passes.

I have a variable that increases in every second (It works with an NSTimer). I want to replace the duraton with this variable, in this line of code:

let action = SKAction.moveToY(120, duration: 3)

But I can't because the duration must be of type NSTimeInterval.

How can I transform my variable (which is Int) to NSTime Interval so it can work properly?

Upvotes: 2

Views: 9279

Answers (1)

Abhinav
Abhinav

Reputation: 38142

NSTimeInterval is defined as:

typealias NSTimeInterval = Double

So, technically, you can define your interval and assign direct integers:

var interval: NSTimeInterval = 3

Upvotes: 6

Related Questions