diff --git a/cocos2dx/platform/iphone/CCDirectorCaller.h b/cocos2dx/platform/iphone/CCDirectorCaller.h index 77be43bf64..f9a6ca330d 100644 --- a/cocos2dx/platform/iphone/CCDirectorCaller.h +++ b/cocos2dx/platform/iphone/CCDirectorCaller.h @@ -24,8 +24,10 @@ #import @interface CCDirectorCaller : NSObject { - id displayLink; + id displayLink; + int interval; } +@property (readwrite) int interval; -(void) startMainLoop; -(void) doCaller: (id) sender; -(void) setAnimationInterval:(double)interval; diff --git a/cocos2dx/platform/iphone/CCDirectorCaller.mm b/cocos2dx/platform/iphone/CCDirectorCaller.mm index 878195f435..628a2c3024 100644 --- a/cocos2dx/platform/iphone/CCDirectorCaller.mm +++ b/cocos2dx/platform/iphone/CCDirectorCaller.mm @@ -36,6 +36,8 @@ static id s_sharedDirectorCaller; @implementation CCDirectorCaller +@synthesize interval; + +(id) sharedDirectorCaller { if (s_sharedDirectorCaller == nil) @@ -51,23 +53,39 @@ static id s_sharedDirectorCaller; [s_sharedDirectorCaller release]; } +-(void) alloc +{ + interval = 1; +} + -(void) dealloc { - [displayLink invalidate]; [displayLink release]; [super dealloc]; } -(void) startMainLoop { - displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:@selector(doCaller:)]; - [displayLink setFrameInterval: 1]; - [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; + // CCDirector::setAnimationInterval() is called, we should invalide it first + [displayLink invalidate]; + displayLink = nil; + + displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:@selector(doCaller:)]; + [displayLink setFrameInterval: self.interval]; + [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; } -(void) setAnimationInterval:(double)interval { - [displayLink setFrameInterval: interval]; + // CCDirector::setAnimationInterval() is called, we should invalide it first + [displayLink invalidate]; + displayLink = nil; + + self.interval = 60.0 * interval; + + displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:@selector(doCaller:)]; + [displayLink setFrameInterval: self.interval]; + [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; } -(void) doCaller: (id) sender diff --git a/cocos2dx/platform/iphone/CCXApplication_iphone.h b/cocos2dx/platform/iphone/CCXApplication_iphone.h index 2729bcb617..407a72e88a 100644 --- a/cocos2dx/platform/iphone/CCXApplication_iphone.h +++ b/cocos2dx/platform/iphone/CCXApplication_iphone.h @@ -57,7 +57,7 @@ public: void run(); - void setAnimationInterval(double interval); + void setAnimationInterval(double interval); /** @brief Get current applicaiton instance. diff --git a/cocos2dx/platform/iphone/CCXApplication_iphone.mm b/cocos2dx/platform/iphone/CCXApplication_iphone.mm index 6b0990c531..b110fd4f63 100644 --- a/cocos2dx/platform/iphone/CCXApplication_iphone.mm +++ b/cocos2dx/platform/iphone/CCXApplication_iphone.mm @@ -89,10 +89,10 @@ namespace cocos2d { [[CCDirectorCaller sharedDirectorCaller] startMainLoop]; } - void CCXApplication::setAnimationInterval(double interval) - { - // TBD - } + void CCXApplication::setAnimationInterval(double interval) + { + [[CCDirectorCaller sharedDirectorCaller] setAnimationInterval: interval ]; + } ////////////////////////////////////////////////////////////////////////// /// Implement static class member diff --git a/cocos2dx/platform/iphone/CCXEGLView_iphone.h b/cocos2dx/platform/iphone/CCXEGLView_iphone.h index d64d18bdfe..ed04ded988 100644 --- a/cocos2dx/platform/iphone/CCXEGLView_iphone.h +++ b/cocos2dx/platform/iphone/CCXEGLView_iphone.h @@ -44,7 +44,6 @@ public: bool isOpenGLReady(); bool canSetContentScaleFactor(); void setContentScaleFactor(float contentScaleFactor); - void setAnimationInterval(double interval); // keep compatible void release(); diff --git a/cocos2dx/platform/iphone/CCXEGLView_iphone.mm b/cocos2dx/platform/iphone/CCXEGLView_iphone.mm index cfa43ab2c3..351d151978 100644 --- a/cocos2dx/platform/iphone/CCXEGLView_iphone.mm +++ b/cocos2dx/platform/iphone/CCXEGLView_iphone.mm @@ -60,11 +60,6 @@ bool CCXEGLView::isOpenGLReady() { [[EAGLView sharedEGLView] setContentScaleFactor:contentScaleFactor]; } - - void CCXEGLView::setAnimationInterval(double interval) - { - [[CCDirectorCaller sharedDirectorCaller ]setAnimationInterval: interval]; - } void CCXEGLView::release() {