[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

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

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
{
// 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

View File

@ -91,7 +91,7 @@ namespace cocos2d {
void CCXApplication::setAnimationInterval(double interval)
{
// TBD
[[CCDirectorCaller sharedDirectorCaller] setAnimationInterval: interval ];
}
//////////////////////////////////////////////////////////////////////////

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