如何画一条线与Cocos2d-iPhone [英] How to draw a line with Cocos2d-iPhone

查看:123
本文介绍了如何画一条线与Cocos2d-iPhone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过尝试完成简单的事情来掌握Cocos2d。在这一点上,我有一个场景,那个场景有一个背景精灵和一个图层。我试图使用drawLine绘制到图层。这是我目前的尝试。

I'm trying to get to grips with Cocos2d by trying to accomplish simple things. At this point, I have a scene, that scene has a background sprite, and a Layer. I'm trying to draw onto the Layer using drawLine. Here's 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

这会产生错误void value not它应该是。所以显然我做错了,但希望你能看到我的推理。

Which generates the error "void value not ignored as it ought to be". So obviously I'm doing it wrong, but hopefully you can see my reasoning.

我也尝试过这个

-(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);
    }
    return self;
}

这不给我一个错误,但它不工作。我知道我不理解一些根本的东西,但任何人都可以指导我在正确的方向?

Which doesn't give me an error, but it doesn't work either. I realise I'm not understanding something fundamental, but can anyone steer me in the right direction?

推荐答案

从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) );

  // ...
}

这篇关于如何画一条线与Cocos2d-iPhone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆