好吧,经过多一点研究,我发现this thread它使用glViewport
设置视口,然后调用[super visit]
为每个视口。
但是,这并不适合我,因为出于某种原因,每个视口的图像都被拉伸了 - 我猜视口已经搞乱了Cocos2d的内部。
我通过定位图层几乎完全使用Cocos2d函数来重做视口,调用[super visit]
并重新定位并再次调用[super visit]
。通过这种与glScissor
结合,我可以模仿视
以供将来参考,下面是我用的代码片段:
-(void) visit
{
glEnable(GL_SCISSOR_TEST);
glPushMatrix();
CGPoint point = ((CCNode*)[toFollow objectAtIndex:1]).position;
self.anchorPoint = ccp(point.x/self.contentSize.width, point.y/self.contentSize.height);
self.rotation = 180.0f;
point = ((CCNode*)[toFollow objectAtIndex:1]).position;
self.position = ccpAdd(ccp(bounds.width/2,bounds.height/4*3),ccp(-point.x, -point.y));
glScissor(0,bounds.height/2,bounds.width,bounds.height/2);
[super visit];
glPopMatrix();
glPushMatrix();
self.anchorPoint = CGPointZero;
self.rotation = 0.0f;
point = ((CCNode*)[toFollow objectAtIndex:0]).position;
self.position = ccpAdd(ccp(bounds.width/2,bounds.height/4),ccp(-point.x, -point.y));
glScissor(0,0,bounds.width,bounds.height/2);
[super visit];
glPopMatrix();
glDisable(GL_SCISSOR_TEST);
//self.rotation = 0.0f;
//[super visit];
}
您可以上传一个示例项目。我不确定如何将此代码用于分屏。 – mikeytdan
您可以在包含所有游戏对象的CCLayer中使用此代码。我找不到原来的项目,我很遗憾地使用这个项目 – tangrs
@tangrs什么包含'toFollow'数组? – dwbrito