Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocos2d iphone 我需要打电话给[convertToGl]吗?_Cocos2d Iphone_Position - Fatal编程技术网

Cocos2d iphone 我需要打电话给[convertToGl]吗?

Cocos2d iphone 我需要打电话给[convertToGl]吗?,cocos2d-iphone,position,Cocos2d Iphone,Position,我正在使用cocos2d,并且我已经将cccnode子类化(我想画圆,这很有效) h //我的.m文件 @实现CCSpriteCircle @综合半径、角度、线段、绘图线中心、颜色 -(id) initWithRadius: (float)radius_ withAngle: (float)angle_ withSegments: (NSUInteger)segments_ withDrawLineToCenter:(BOOL)drawLineToCenter_ { if( (self=[su

我正在使用cocos2d,并且我已经将cccnode子类化(我想画圆,这很有效) h

//我的.m文件

@实现CCSpriteCircle @综合半径、角度、线段、绘图线中心、颜色

-(id) initWithRadius: (float)radius_ withAngle: (float)angle_ withSegments: (NSUInteger)segments_ withDrawLineToCenter:(BOOL)drawLineToCenter_
{
 if( (self=[super init])) {
  self.radius = radius_;
  self.angle = angle_;
  self.segments = segments_;
  self.drawLineToCenter = drawLineToCenter_;
  //[self draw];
 }

 return self;
}

-(void)draw {

 glLineWidth(1);
 glColor4ub(cColor.r, cColor.g, cColor.b, cColor.a);
 ccDrawCircle(ccp(self.position.x,self.position.y), radius, angle, segments, drawLineToCenter);
 // restore original values
 glLineWidth(1);
 glColor4ub(255,255,255,255);
 glPointSize(1);

}
@end
一切正常,但如果我将ccspritecircle的中心设置为480(即屏幕的末尾),它不会出现,但如果我将其设置为200px,则它位于屏幕的末尾

如果我像这样更改helloworld场景中的位置代码: 发件人:

圆位置=ccp(480,0)

致:


那我就看不到圆圈了。我做错什么了吗?

如果您的唯一目的是绘制一个自定义圆,而不使用任何其他形式的图形(图像文件),那么您应该为CCNode子类,而不是CCSprite子类。CCSprite是一种特殊类型的CCNode,用于处理图形文件的加载和显示

您还应该从覆盖内部调用“[super draw]”,以确保正确完成额外的处理-这可以在代码之前或之后进行,具体取决于它对最终结果的影响

ccDrawCircle已经在将x/y坐标转换为GL空间,因此您也不必担心这一点

不过,您的CCNode的主播点和位置可能是一个因素。默认的0.5/0.5锚点应将圆的中心设置在节点的x/y位置,因此半径为32的(480,0)将在屏幕的右下角放置一个64x64的圆(纵向),并且只能看到圆的左上象限

您说将其设置为200px会将其放置在屏幕的末尾,而没有看到圆是如何初始化的,很难确定为什么会发生这种情况-但它很可能与您使用的圆的半径有关

请记住,更改锚点可能不会影响圆的渲染,因为“绘制”方法没有考虑当前锚点,因此可能会将圆放置在x/y位置,而与锚点设置无关

-(id) initWithRadius: (float)radius_ withAngle: (float)angle_ withSegments: (NSUInteger)segments_ withDrawLineToCenter:(BOOL)drawLineToCenter_
{
 if( (self=[super init])) {
  self.radius = radius_;
  self.angle = angle_;
  self.segments = segments_;
  self.drawLineToCenter = drawLineToCenter_;
  //[self draw];
 }

 return self;
}

-(void)draw {

 glLineWidth(1);
 glColor4ub(cColor.r, cColor.g, cColor.b, cColor.a);
 ccDrawCircle(ccp(self.position.x,self.position.y), radius, angle, segments, drawLineToCenter);
 // restore original values
 glLineWidth(1);
 glColor4ub(255,255,255,255);
 glPointSize(1);

}
@end
circle_.position = [[CCDirector sharedDirector] convertToGL: CGPointMake(480,0)];