mirror of https://github.com/axmolengine/axmol.git
[iphone]: frame control
This commit is contained in:
parent
dd979a4ed9
commit
cb7a0e553a
|
@ -25,7 +25,9 @@
|
|||
|
||||
@interface CCDirectorCaller : NSObject {
|
||||
id displayLink;
|
||||
int interval;
|
||||
}
|
||||
@property (readwrite) int interval;
|
||||
-(void) startMainLoop;
|
||||
-(void) doCaller: (id) sender;
|
||||
-(void) setAnimationInterval:(double)interval;
|
||||
|
|
|
@ -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
|
||||
{
|
||||
// CCDirector::setAnimationInterval() is called, we should invalide it first
|
||||
[displayLink invalidate];
|
||||
displayLink = nil;
|
||||
|
||||
displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:@selector(doCaller:)];
|
||||
[displayLink setFrameInterval: 1];
|
||||
[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
|
||||
|
|
|
@ -91,7 +91,7 @@ namespace cocos2d {
|
|||
|
||||
void CCXApplication::setAnimationInterval(double interval)
|
||||
{
|
||||
// TBD
|
||||
[[CCDirectorCaller sharedDirectorCaller] setAnimationInterval: interval ];
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -44,7 +44,6 @@ public:
|
|||
bool isOpenGLReady();
|
||||
bool canSetContentScaleFactor();
|
||||
void setContentScaleFactor(float contentScaleFactor);
|
||||
void setAnimationInterval(double interval);
|
||||
|
||||
// keep compatible
|
||||
void release();
|
||||
|
|
|
@ -61,11 +61,6 @@ bool CCXEGLView::isOpenGLReady()
|
|||
[[EAGLView sharedEGLView] setContentScaleFactor:contentScaleFactor];
|
||||
}
|
||||
|
||||
void CCXEGLView::setAnimationInterval(double interval)
|
||||
{
|
||||
[[CCDirectorCaller sharedDirectorCaller ]setAnimationInterval: interval];
|
||||
}
|
||||
|
||||
void CCXEGLView::release()
|
||||
{
|
||||
[CCDirectorCaller destroy];
|
||||
|
|
Loading…
Reference in New Issue