Ios 在Cocos2d中绘制一条线
我是Cocos2d的新手。 我尝试在Cocos2d中画一条简单的线:Ios 在Cocos2d中绘制一条线,ios,objective-c,cocos2d-iphone,line,draw,Ios,Objective C,Cocos2d Iphone,Line,Draw,我是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
-(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:
C99中函数“ccDrawLine”的隐式声明无效
正如@learncos2D所建议的,您可以通过在visit函数中调用cocos2d提供的内置绘图函数来使用它们
#import "CCDrawingPrimitives.h"
-(void) visit{
[super visit];
ccDrawLine(ccp(0,100), ccp(320,150));
}
正如@learncos2D所建议的,您可以通过在visit函数中调用cocos2d提供的内置绘图函数来使用它们
#import "CCDrawingPrimitives.h"
-(void) visit{
[super visit];
ccDrawLine(ccp(0,100), ccp(320,150));
}
我将扩展@abhineetprasad答案。首先-应在访问函数结束时调用绘图函数,而不是在绘图中:
-(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之前的版本中是否属实 我将扩展@abhineetprasad答案。首先-应在访问函数结束时调用绘图函数,而不是在绘图中:
-(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之前的版本中是否属实 隐式声明警告意味着我需要一个显式声明,即包含OpenGL头文件,或者在您的情况下包含Cocos2d头文件。是的,我的意思是警告:。我需要什么隐式的呢?这看起来像OpenGLES1.1代码,在CoCoS2D2v2.x和更高版本中不起作用,并且使用OpenGLES2.0。此外,cocos2d还具有内置绘图功能,搜索ccDrawLine、ccDrawCircle等。如果CCDrawNode可用,甚至更好,因为它可以更高效地渲染绘制的原语。隐式声明警告意味着我需要显式声明,即包括OpenGL头文件,或者在您的情况下包括cocos2d头文件。是,我的意思是警告:。我需要什么隐式的呢?这看起来像OpenGLES1.1代码,在CoCoS2D2v2.x和更高版本中不起作用,并且使用OpenGLES2.0。cocos2d还具有内置的绘图功能,搜索ccDrawLine、ccDrawCircle等。如果CCDrawNode可用,甚至更好,因为它可以更高效地渲染绘制的基本体。