matsmats matsmats - 25 days ago 9x
iOS Question

How to set up game loop in Swift

To set up a game loop in Objective-C I learnt that I should set up a CADisplayLink

updater = [CADisplayLink displayLinkWithTarget:self selector:@selector(gameLoop) ];
[updater setFrameInterval: 1];
[updater addToRunLoop: [NSRunLoop currentRunLoop] forMode: NSRunLoopCommonModes];

How do I do this in Swift?

I have tried to Google this but I cannot find any examples of this.


Pretty much just a direct translation from Objective-C to Swift with a few tweaks.

import QuartzCore
var updater = CADisplayLink(target: self, selector: Selector("gameLoop"))
    updater.frameInterval = 1
    updater.addToRunLoop(NSRunLoop.currentRunLoop(), forMode: NSRunLoopCommonModes)