游戏框架基本完成,而且能够顺利运行,但我想创建一个矩形的图层,方便未来的游戏升级或者维护工作。这些矩形会在编译时被启用,为开发者显示屏幕的聚光区(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",来解决这种问题?
原问题:Adding rectangles to a CCScene - cocos2d
Answer: FuzzyBunnySlippers
I think OpenGL ES 2.0 will not support GL_LINE_SMOOTH, only the Desktop Version supports it. So I think, you can use the following drawing methods to draw rectangles and other things:
You can also leave the version blank:
Here are some sample codes for your reference. I created a project (a version lower than cocos2d 1.01) and added the following code:
The effect achieved is as follows:
Answer: godel9
You can use the CCLayerColor class to add a solid color rectangle with just a few lines of code and no need to create other subclasses: