NSDisplayLinkUpdateLoop 1.0.1

NSDisplayLinkUpdateLoop 1.0.1

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Dec 2014

Maintained by Ian Grossberg.



  • By
  • Ian G

NSDisplayLinkUpdateLoop is a simple object providing notification from your application whenever the screen is updated.

This simplifies building your own update loops, provides a higher level of precision than an NSTimer and allows syncronization with screen updates (aside: a neat read by Fabien Sanglard about an issue with NSTimer and his alternative workaround).

To use NSDisplayLinkUpdateLoop first have your object inherit and implement the NSDisplayLinkUpdateLoopDelegate interface

#include "NSDisplayLinkUpdateLoop.h"

@interface IWannaUpdate : NSObject< NSDisplayLinkUpdateLoopDelegate >

...

@implementation IWannaUpdate
-( void )update:( NSTimeInterval )deltaTime
{
...
}

Next instantiate an NSDisplayLinkUpdateLoop and have your object subscribe

-( void )startUpdates
{
    IWannaUpdate* updateMe = [ [ IWannaUpdate alloc ] init ];

    updateLoop = [ [ NSDisplayLinkUpdateLoop alloc ] init ];
[ updateLoop subscribe:updateMe ];
}

To stop receiving update calls

[ updateLoop unsubscribe:updateMe ];

Easy!

Note

NSDisplayLinkUpdateLoop retains its subscribers, make sure you understand when you're creating a reference ownership loop!