假设我的游戏中关卡的宽度是屏幕宽度的三倍,而我的玩家从最左边开始。我应该如何在这个关卡开始时从右边缘开始实现相机飞越以滚动整个世界,以便玩家知道未来会发生什么?
我在这里遇到了这篇文章http://www.cocos2d-iphone.org/forum/topic/9568似乎很有用,借用了其中的代码块并将其放入我的GameWorldLayer
,但它没有用。我基本上只看到黑屏。怎么了?什么是更好的实现方式?
-(void)visit {
CGSize screenDims = [[CCDirector sharedDirector] winSizeInPixels];
CGPoint camPos = gameCamera.position;
float camZoom = gameCamera.zoom;
[[CCDirector sharedDirector] setProjection:kCCDirectorProjectionCustom];
//now set your projection
kmGLMatrixMode(KM_GL_PROJECTION);
//save current projection state
kmGLPushMatrix();
kmGLLoadIdentity();
kmMat4 orthoMat;
kmMat4OrthographicProjection(&orthoMat,
camPos.x -screenDims.width/(2*camZoom),
camPos.x +screenDims.width/(2*camZoom),
camPos.y +screenDims.height/(2*camZoom),
camPos.y -screenDims.height/(2*camZoom),
-1000,
1000);
kmGLMatrixMode(KM_GL_MODELVIEW);
kmGLLoadIdentity();
[super visit];
//put it back
kmGLMatrixMode(KM_GL_PROJECTION);
kmGLPopMatrix();
kmGLMatrixMode(KM_GL_MODELVIEW);
kmGLLoadIdentity();
}