I have a background picture for a scene. I want to draw some lines above it. I can now draw lines in the draw function. But I find that lines can only be visible when there is no background picture. Can anybody tell me how to draw lines with background picture?
Thank you.
How to draw a line above a background picture?
(6 posts) (3 voices)-
Posted 1 year ago #
-
Yep, you have to make sure that you draw them after the background gets drawn, which is normally done by
[super draw]. Like so:- (void)draw { [super draw]; glColor4ub(255,0,255,255); // Or whatever drawing setup you need ccDrawLine(ccp(100,100), ccp(200,200)); }Posted 1 year ago # -
As far as I know, drawing is done on layer 0. Anything below that layer will be drawn over, and anything above it will overlap the drawing. When you add your background picture to the layer, just add it like
[self addChild:bgSprite z:-1];I wasn't aware of the [super draw] trick. Will give it a go!
Posted 1 year ago # -
Oh yeah, I forgot that's what you normally do with
drawwhen you're layering nodes. I was thinking of when you have something that implementsCCTextureProtocol(likeCCSprite) and want to do the drawing as part of that object. (Probably not a real common occurrence, admittedly.)Posted 1 year ago # -
Thank you Tim, and thank you Andrew.
I guess I have got what I wanted.I guess the statement Andrew wrote will solve my problem.
quote: [self addChild:bgSprite z:-1];I will test it when I am home today and I will report it to you here.
Thank you again, Andrew and Tim.
Posted 1 year ago # -
Andrew and Tim
Thank you again for your advices. I tested and it did solve my problem.
Thank you.
Posted 1 year ago #
Reply
You must log in to post.