开发者

How to draw line in topmost z-oder

I want to draw line connect two sprites, but i can not do that in this case:

//add Map Background
        map = [CCTMXTiledMap tiledMapWithTMXFile:@"orthogonal-test-zorder.tmx"];
        [self addChild:map z:1 tag:kTagTileMap];
//o开发者_Go百科verite draw function
- (void)draw {

    glColor4f(0.8, 1.0, 0.76, 1.0);  
    glEnable(GL_LINE_SMOOTH);
    ccDrawLine( ccp(0, 0), ccp(150, 150) );
}

the line is not shown on screen, if i remove map background , it's shown.


I don't know Cocos2D so this is just wild guessing, but the z parameter of [self addChild:map z:1 tag:kTagTileMap]; seems to be a z offset. Since 1 would be in front of 0 (the likely default), your map would render in front of your line. Try [self addChild:map z:-1 tag:kTagTileMap];


I've encounted same problem 2 days ago.

My solution is to make a seperate MyLineLayer which only draw the line. Then you can set the z-index of the CCLayer to the top.

I think that using an enveloped MyLineLayer would be better than make the z-index of the tile map smaller.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜