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 {
|
@interface CCDirectorCaller : NSObject {
|
||||||
id displayLink;
|
id displayLink;
|
||||||
|
int interval;
|
||||||
}
|
}
|
||||||
|
@property (readwrite) int interval;
|
||||||
-(void) startMainLoop;
|
-(void) startMainLoop;
|
||||||
-(void) doCaller: (id) sender;
|
-(void) doCaller: (id) sender;
|
||||||
-(void) setAnimationInterval:(double)interval;
|
-(void) setAnimationInterval:(double)interval;
|
||||||
|
|
|
@ -36,6 +36,8 @@ static id s_sharedDirectorCaller;
|
||||||
|
|
||||||
@implementation CCDirectorCaller
|
@implementation CCDirectorCaller
|
||||||
|
|
||||||
|
@synthesize interval;
|
||||||
|
|
||||||
+(id) sharedDirectorCaller
|
+(id) sharedDirectorCaller
|
||||||
{
|
{
|
||||||
if (s_sharedDirectorCaller == nil)
|
if (s_sharedDirectorCaller == nil)
|
||||||
|
@ -51,23 +53,39 @@ static id s_sharedDirectorCaller;
|
||||||
[s_sharedDirectorCaller release];
|
[s_sharedDirectorCaller release];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-(void) alloc
|
||||||
|
{
|
||||||
|
interval = 1;
|
||||||
|
}
|
||||||
|
|
||||||
-(void) dealloc
|
-(void) dealloc
|
||||||
{
|
{
|
||||||
[displayLink invalidate];
|
|
||||||
[displayLink release];
|
[displayLink release];
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void) startMainLoop
|
-(void) startMainLoop
|
||||||
{
|
{
|
||||||
|
// CCDirector::setAnimationInterval() is called, we should invalide it first
|
||||||
|
[displayLink invalidate];
|
||||||
|
displayLink = nil;
|
||||||
|
|
||||||
displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:@selector(doCaller:)];
|
displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:@selector(doCaller:)];
|
||||||
[displayLink setFrameInterval: 1];
|
[displayLink setFrameInterval: self.interval];
|
||||||
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
|
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void) setAnimationInterval:(double)interval
|
-(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
|
-(void) doCaller: (id) sender
|
||||||
|
|
|
@ -91,7 +91,7 @@ namespace cocos2d {
|
||||||
|
|
||||||
void CCXApplication::setAnimationInterval(double interval)
|
void CCXApplication::setAnimationInterval(double interval)
|
||||||
{
|
{
|
||||||
// TBD
|
[[CCDirectorCaller sharedDirectorCaller] setAnimationInterval: interval ];
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -44,7 +44,6 @@ public:
|
||||||
bool isOpenGLReady();
|
bool isOpenGLReady();
|
||||||
bool canSetContentScaleFactor();
|
bool canSetContentScaleFactor();
|
||||||
void setContentScaleFactor(float contentScaleFactor);
|
void setContentScaleFactor(float contentScaleFactor);
|
||||||
void setAnimationInterval(double interval);
|
|
||||||
|
|
||||||
// keep compatible
|
// keep compatible
|
||||||
void release();
|
void release();
|
||||||
|
|
|
@ -61,11 +61,6 @@ bool CCXEGLView::isOpenGLReady()
|
||||||
[[EAGLView sharedEGLView] setContentScaleFactor:contentScaleFactor];
|
[[EAGLView sharedEGLView] setContentScaleFactor:contentScaleFactor];
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCXEGLView::setAnimationInterval(double interval)
|
|
||||||
{
|
|
||||||
[[CCDirectorCaller sharedDirectorCaller ]setAnimationInterval: interval];
|
|
||||||
}
|
|
||||||
|
|
||||||
void CCXEGLView::release()
|
void CCXEGLView::release()
|
||||||
{
|
{
|
||||||
[CCDirectorCaller destroy];
|
[CCDirectorCaller destroy];
|
||||||
|
|
Loading…
Reference in New Issue