How to draw a line with COCOS2D-iPhone

I try to master Cocos2d by trying to accomplish simple things. At this point, I have a scene, and that scene has a background sprite and a layer. I tried to draw the layer with drawLine. This is my current attempt.

@implementation MyLayer
-(id)init{
self = [super init];
if(self != nil){
glColor4f(0.8, 1.0, 0.76, 1.0);
glLineWidth(2.0f);
CocosNode *line = drawLine(10.0f, 100.0f,400.0f,27.0f) ;
[self addChild:line z:1];
}
return self;
}
@end

This will produce an error ” void value not ignored as it should be”. So obviously I did something wrong, but hope you can see my reasoning.

I tried it too

-(id)init{
self = [super init];
if(self != nil){
glColor4f(0.8, 1.0, 0.76, 1.0);
glLineWidth(2.0f);
drawLine(10.0f, 100.0f,400.0f,27.0f);< br /> }
return self;
}

Which doesn’t give me an error, but it doesn’t work either. I realize that I don’t understand some fundamental things, but can anyone guide me in the right direction?

From cocos2d drawPrimitivesTest.m:

- (void)draw {
// ...

// draw a simple line
// The default state is:
// Line Width: 1
// color: 255,255,255,255 (white, non-transparent)
// Anti-Aliased
glEnable(GL_LINE_SMOOTH);
ccDrawLine( ccp(0, 0), ccp(s.width, s.height) );

// ...
}

I tried to complete Simple things to master Cocos2d. At this point, I have a scene, and that scene has a background sprite and a layer. I tried to draw the layer with drawLine. This is my current attempt.

@implementation MyLayer
-(id)init{
self = [super init];
if(self != nil){
glColor4f(0.8, 1.0, 0.76, 1.0);
glLineWidth(2.0f);
CocosNode *line = drawLine(10.0f, 100.0f,400.0f,27.0f) ;
[self addChild:line z:1];
}
return self;
}
@end

This will produce an error ” void value not ignored as it should be”. So obviously I did something wrong, but hope you can see my reasoning.

I tried it too

-(id)init{
self = [super init];
if(self != nil){
glColor4f(0.8, 1.0, 0.76, 1.0);
glLineWidth(2.0f);
drawLine(10.0f, 100.0f,400.0f,27.0f);< br /> }
return self;
}

Which doesn’t give me an error, but it doesn’t work either. I realize that I don’t understand some fundamental things, but can anyone guide me in the right direction?

From cocos2d drawPrimitivesTest.m:

- (void)draw {
// ...

// draw a simple line
// The default state is:
// Line Width: 1
// color: 255,255,255,255 (white, non-transparent)
// Anti-Aliased
glEnable(GL_LINE_SMOOTH);
ccDrawLine( ccp(0, 0), ccp(s.width, s.height) );

// ...
}

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3706 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.