[iphone]: frame control

This commit is contained in:
minggo 2011-01-21 17:33:15 +08:00
parent dd979a4ed9
commit cb7a0e553a
6 changed files with 31 additions and 17 deletions

View File

@ -24,8 +24,10 @@
#import <Foundation/Foundation.h>
@interface CCDirectorCaller : NSObject {
id displayLink;
id displayLink;
int interval;
}
@property (readwrite) int interval;
-(void) startMainLoop;
-(void) doCaller: (id) sender;
-(void) setAnimationInterval:(double)interval;

View File

@ -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

View File

@ -57,7 +57,7 @@ public:
void run();
void setAnimationInterval(double interval);
void setAnimationInterval(double interval);
/**
@brief Get current applicaiton instance.

View File

@ -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

View File

@ -44,7 +44,6 @@ public:
bool isOpenGLReady();
bool canSetContentScaleFactor();
void setContentScaleFactor(float contentScaleFactor);
void setAnimationInterval(double interval);
// keep compatible
void release();

View File

@ -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];