我是Cocos2d的新手。 我尝试在Cocos2d中绘制一个简单的行:
-(void)draw
{
[super draw];
glColor4ub(0,0,0,255);
glLineWidth(2);
glColor4f(1.0, 1.0, 0.5, 1);
ccDrawLine(ccp(0,100), ccp(320,150));
}
但是显示警告:
HelloWorldScene.m:70:5:隐式声明函数' glColor4ub' 在C99中无效HelloWorldScene.m:72:5:隐式声明 功能' glColor4f'在C99中无效HelloWorldScene.m:73:5: 隐含的函数声明&#c; ccDrawLine'在C99中无效
答案 0 :(得分:3)
我将延长@abhineetprasad的答案。首先 - 你应该在访问函数的末尾而不是在draw中调用绘图函数:
-(void) visit
{
// call implementation of the super class to draw self and all children, in proper order
[super visit];
//custom draw code put below [super visit] will draw over the current node and all of its children
}
比你可以使用像ccDrawLine或ccDrawColor4F这样的函数来正确地绘制线条/设置颜色。所以,例如:
-(void) visit
{
// call implementation of the super class to draw self and all children, in proper order
[super visit];
//custom draw code put below [super visit] will draw over the current node and all of its children
//set color to red
ccDrawColor4F(1.0f, 0.0f, 0.0f, 1.0f);
//draw the line
ccDrawLine(ccp(0,0), ccp(320, 150));
}
在cocos2d-v3中,CCDrawingPrimitives.h已经包含在" cocos2d.h"头文件。 我不确定在之前的版本中它是否适用于Cocos2d的v3.0。
答案 1 :(得分:2)
正如@ LearnCocos2d所建议的那样,你可以使用cocos2d提供的内置绘图函数,在访问函数中调用它们。
#import "CCDrawingPrimitives.h"
-(void) visit{
[super visit];
ccDrawLine(ccp(0,100), ccp(320,150));
}