开发者社区> 问答> 正文

如何在CCScene中添加矩形?

游戏框架基本完成,而且能够顺利运行,但我想创建一个矩形的图层,方便未来的游戏升级或者维护工作。这些矩形会在编译时被启用,为开发者显示屏幕的聚光区(scene hotspots)。
我尝试创建一个新的CCLayer,然后将它的绘图方法变为:

  • (void)draw
    {

    glEnable(GL_LINE_SMOOTH);
    glColor4ub(255, 255, 255, 255);
    glLineWidth(2);
    CGPoint vertices2[] = { ccp(79,299), ccp(134,299), ccp(134,229), ccp(79,229) };
    ccDrawPoly(vertices2, 4, YES);

    }

但是Xcode显示:"Use of Undeclared identifier GL_LINE_SMOOTH"。
我不想因为这个问题再单独创建一个精灵的image,有没有其他的方法,类似于使用"CGContextAddRect",来解决这种问题?

展开
收起
a123456678 2016-07-20 17:49:43 2345 0
1 条回答
写回答
取消 提交回答
  • 我觉得OpenGL ES 2.0不会支持GL_LINE_SMOOTH,只有Desktop Version版本中支持它。所以我觉得,你可以使用如下绘图方法来绘制矩形和其它的东西:

    void ccDrawPoint (CGPoint point);
    void ccDrawPoints (const CGPoint *points, NSUInteger numberOfPoints);
    void ccDrawLine (CGPoint origin, CGPoint destination);
    void ccDrawRect (CGPoint origin, CGPoint destination);
    
    void ccDrawPoly (const CGPoint *vertices, NSUInteger numOfVertices, BOOL closePolygon);
    void ccDrawCircle (CGPoint center, float radius, float angle, NSUInteger segments, BOOL drawLineToCenter);
    你也可以不填写版本:
    
    void ccDrawSolidRect (CGPoint origin, CGPoint destination, ccColor4F color);
    void ccDrawSolidPoly (const CGPoint *poli, NSUInteger numberOfPoints, ccColor4F color);
    2019-07-17 19:59:08
    赞同 展开评论 打赏
问答分类:
问答地址:
相关产品:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载