Cocos2d iphone Cocos2d中的中风

Cocos2d iphone Cocos2d中的中风,cocos2d-iphone,Cocos2d Iphone,如何在Cocos2d中划一条线?是否可以将笔划转换为精灵?您可以通过覆盖“绘制”方法来绘制线条,这反过来会产生您想要的“笔划”效果。这个问题有点缺乏细节,所以我会尽量利用它 假设您想在屏幕上画一条简单的线,可以执行以下操作: @interface MyLine: CCNode { CGRect lineRect; } @property(nonatomic) CGRect lineRect; +(id)lineWithRect:(CGRect)rect; @end @implementat

如何在Cocos2d中划一条线?是否可以将笔划转换为精灵?

您可以通过覆盖“绘制”方法来绘制线条,这反过来会产生您想要的“笔划”效果。这个问题有点缺乏细节,所以我会尽量利用它

假设您想在屏幕上画一条简单的线,可以执行以下操作:

@interface MyLine: CCNode
{
  CGRect lineRect;
}
@property(nonatomic) CGRect lineRect;
+(id)lineWithRect:(CGRect)rect;
@end

@implementation MyLine
@synthesize lineRect
+(id)lineWithRect:(CGRect)rect
{
  MyLine *node = [MyLine node];
  [node setRect: rect];
  return node];
}
-(void)draw
{
  glEnable(GL_LINE_SMOOTH);
  ccDrawLine(ccp(rect.origin.x, rect.origin.y), ccp(rect.size.width, rect.size.height));
}
@end
使用此类,您可以调用:

MyLine *line = [MyLine lineWithRect:CGRectMake(0, 0, winSize.width, winSize.height)];
然后从屏幕的左下角到右上角画一条线

您不会将其转换为“精灵”,因为这样做是不必要的-但您可以将其视为游戏中的任何其他图形,因为它现在是CCNode的自己子类。。。包含所有与之相关的优点(定位等)