以下是我所想要得到的效果:
但我实际得到的却是这么个玩意儿:
找了很久很久,起初还以为是弄乱了opengl的状态机,
但是其他元素的渲染却并没有出什么问题啊,很奇怪,很纠结,很揪心。。
-(void) drawPolygon:(b2Fixture*)fixture xf:(b2Transform)xf color:(b2Color)color {
b2PolygonShape *poly = (b2PolygonShape*)fixture->GetShape();
int32 vertexCount = poly->m_vertexCount;
b2Vec2 vertices[b2_maxPolygonVertices];
for (int32 i = 0; i < vertexCount; ++ i) {
vertices[i] =b2Mul(xf, poly->m_vertices[i]);
vertices[i] +=b2Vec2(0.5f,30.0f -0.5f);
vertices[i] *=_gCfg.multiplyFactor /4;
}
glColor4f(color.r, color.g, color.b,_littleMapContentOpacity);
glVertexPointer(2, GL_FLOAT, 0, vertices);
glDrawArrays(GL_TRIANGLE_FAN,0, vertexCount);
}
后来发现是因为_littleMapContentOpacity这个成员变量在init方法里面没有被赋初值,着实害死我不少脑细胞~
// BYRender.h
@interface BYRender :NSObject {
GCfg *_gCfg;
BOOL _isCutLineValid; // 切割不合格的话会产生一道红色的残影线~
int _durationTimes;
float _touchPathMaxWidth;
float _littleMapContentOpacity; // 小地图内容的透明度~
int _cutLineDurationTimes;
}
@propertyBOOL isCutLineValid;
@propertyfloat touchPathMaxWidth;
@propertyfloat littleMapContentOpacity;
@propertyint cutLineDurationTimes;
......
// BYRender.mm
#import"BYRender.h"
@implementation BYRender
@synthesize isCutLineValid =_isCutLineValid;
@synthesize touchPathMaxWidth =_touchPathMaxWidth;
@synthesize littleMapContentOpacity =_littleMapContentOpacity;
@synthesize cutLineDurationTimes =_cutLineDurationTimes;
+ (BYRender*) getInstance {
staticBYRender *instance;
@synchronized(self) {
if (!instance) {
instance = [[BYRenderalloc]init];
}
}
return instance;
}
- (id) init {
if ((self = [superinit])) {
_gCfg = [GCfg getInstance];
_isCutLineValid =YES;
_durationTimes =0;
_littleMapContentOpacity = [_gCfgffk:@"littleMapContentOpacity"];
}
returnself;
}
......
还有一个要注意的问题:
(有些小细节不注意影响到了程序逻辑的话,找起来是很费劲的,必须要未雨绸缪)
在判断 NSString 是否等于 @"" 之前,最好还是先判断一下其是否为 nil~
if(valueStr!=nil && ![valueStr isEqualToString:@""]) {}