我正在使用 CCTansitionPageTurn 在场景之间翻转。它适用于大多数场景,但我有一个用 gl 绘制的着色场景。着色开始后,CCTransitionPageTurn 不适用于任何场景过渡,即使是之前效果很好的过渡。(我仍然可以移动到另一个场景就好了,但是翻页效果坏了)。
我认为这可能与在调用转换之前更改 gl 状态有关,但恢复默认 gl 状态不起作用。代码中可能有很多地方存在问题,但这里有一些我正在使用 gl 的代码。
/* ColoringGameScene : CCScene, which handles drawing menus and other cool UI things */
// In init
CCLayerColor *layer = [CCLayerColor layerWithColor:ccc4(255, 255, 255, 255)];
[self addChild:layer];
TouchDraw *drawObj = [TouchDraw node];
[drawObj setDrawPoints:_drawPoints];
[layer addChild:drawObj z:999];
// In -(void)ccTouchMoved:(UITouch *) touch withEvent:(UIEvent *)event
// drawPoints, an array of points to draw is updated. drawObj has a reference to this array
/* In TouchDraw : CCNode, which handles gl drawing */
// In init
glEnable(GL_LINE_SMOOTH);
glEnable(GL_POINT_SMOOTH);
glEnable(GL_POINT_SMOOTH_HINT);
glEnable(GL_LINE_SMOOTH_HINT);
glHint(GL_POINT_SMOOTH_HINT,GL_NICEST);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_BLEND_COLOR);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glLineWidth(8);
glPointSize(8);
// elsewhere
-(void)drawCircle:(CGPoint)center radius:(float)r arc:(float)a line:(NSUInteger)segs lineToCenter: (BOOL)drawLineToCenter
{
int additionalSegment = 1;
if (drawLineToCenter)
additionalSegment++;
const float coef = 2.0f * (float)M_PI/segs;
GLfloat *vertices = calloc( sizeof(GLfloat)*2*(segs+2), 1);
if( ! vertices )
return;
for(NSUInteger i=0;i<=segs;i++)
{
float rads = i*coef;
GLfloat j = r * cosf(rads + a) + center.x;
GLfloat k = r * sinf(rads + a) + center.y;
vertices[i*2] = j * CC_CONTENT_SCALE_FACTOR();
vertices[i*2+1] =k * CC_CONTENT_SCALE_FACTOR();
}
vertices[(segs+1)*2] = center.x * CC_CONTENT_SCALE_FACTOR();
vertices[(segs+1)*2+1] = center.y * CC_CONTENT_SCALE_FACTOR();
glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, vertices);
glDrawArrays(GL_TRIANGLE_FAN, 0, (GLsizei) segs+additionalSegment);
// restore default state
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_TEXTURE_2D);
free( vertices );
}
-(void)draw
{
[super draw];
if ([drawPoints count])
{
for(int i = 0; i < [drawPoints count]; i += 4)
{
CGPoint point0 = CGPointFromString([drawPoints objectAtIndex:i]);
CGPoint point1 = CGPointFromString([drawPoints objectAtIndex:i+1]);
CGPoint point2 = CGPointFromString([drawPoints objectAtIndex:i+2]);
CGPoint point3 = CGPointFromString([drawPoints objectAtIndex:i+3]);
glColor4f(255.0f/255.0f, 0.0f/255.0f, 0.0f/255.0f, 1.0f); // Red
glLineWidth(8);
glPointSize(8);
// various calls to drawCirle and ccDrawCubicBezier
//default
glColor4f(0.0f/255.0f, 0.0f/255.0f, 0.0f/255.0f, 0.0f);
}
}
}
让我知道更多代码是否会有所帮助。