cocos2d ccDrawPoly在CCSprite上

Ale*_*nov 1 drawing z-index sprite cocos2d-iphone

如何在cocos2d 1.1中设置z-index到ccDrawPoly()来在场景中的所有CCSprite上面绘制?

-(void)draw
{
    CGSize screenSize = [[CCDirector sharedDirector] winSize];
    glEnable(GL_LINE_SMOOTH);
    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
    glColor4ub(0, 0, 255, 255);
    glLineWidth(2);
    CGPoint vertices2[] = { ccp(0,0), ccp(0,screenSize.height*0.5), ccp(screenSize.width*0.5,screenSize.height*0.5), ccp(screenSize.width*0.5,0) };
    ccDrawPoly(vertices2, 4, YES);

}
Run Code Online (Sandbox Code Playgroud)

Lea*_*s2D 5

有几种方法可以实现这一目标.假设在您自己的CCNode子类中覆盖了draw方法,那么:

  • 添加drawPoly节点,其az顺序大于任何sprite的z顺序
  • 将drawPoly节点添加到单独的图层(或节点)中,其绘制顺序高于具有精灵的图层

如果在包含sprite作为子节点的类中重写draw方法,则应该覆盖visit方法.然后在运行自定义绘制多边形代码之前先调用[super visit]:

-(void) visit
{
    // draw node and children first
    [super visit];

    // draw custom code on top of node and its children
    ccDrawPoly( … );
}
Run Code Online (Sandbox Code Playgroud)