如何在CGRect数组中绘制所有矩形?我到目前为止的代码是: 在我的init方法中:
rec1 = CGRectMake(50, 400, 30, 30);
CGRect startingRect = rec1;
int count = 48;
CGRect rectArray[count];
rectArray[0] = startingRect;
CGRect oneRect = rectArray[0];
int i;
for (i = 1; i < count; i++) {
oneRect.origin.x += 40;
if (oneRect.origin.x+oneRect.size.width > size.width) {
oneRect.origin.x = startingRect.origin.x;
oneRect.origin.y -= 40;
}
rectArray[i] = oneRect;
}
[self draw];
在我的绘制方法中:
glColor4f(1.0, 0, 0, 1.0);
glLineWidth(1.0f);
[self drawRectange:rec1];
并在我的drawRectangle方法中:
问题是,由于draw方法会覆盖原始方法(至少就是我认为的那样),我无法修改它以接受CGRect参数,因此它可以为每个rect向drawRentangle方法发送一条消息。有人可以帮帮我吗?非常感谢。
glColor4f(1.0, 0.0, 0.0, 1.0);
CGPoint vertices[4] = {
ccp(rect.origin.x, rect.origin.y),
ccp(rect.origin.x+rect.size.width, rect.origin.y),
ccp(rect.origin.x+rect.size.width, rect.origin.y+rect.size.height),
ccp(rect.origin.x, rect.origin.y+rect.size.height)
};
ccDrawPoly(vertices, 4, YES);
glVertexPointer(2, GL_FLOAT, 0, vertices);
CC_ENABLE_DEFAULT_GL_STATES();
答案 0 :(得分:0)
CGRect rectArray[count];
NSUInteger index = count;
while (index--)
UIRectFrame(rectArray[index]);
答案 1 :(得分:0)
为什么不使用NSMutableArray
作为实例变量,以便可以在draw方法中访问它?