Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get cocos2d to draw all rectangles in an array
    text
    copied!<p>How can I draw all the rectangles in a CGRect array? The code I have so far is: in my init method:</p> <blockquote> <p><code>rec1 = CGRectMake(50, 400, 30, 30);</code><br> <code>CGRect startingRect = rec1;</code><br> <code>int count = 48;</code><br> <code>CGRect rectArray[count];</code><br> <code>rectArray[0] = startingRect;</code><br> <code>CGRect oneRect = rectArray[0];</code><br> <code>int i;</code><br> <code>for (i = 1; i &lt; count; i++) {</code><br> <code>oneRect.origin.x += 40;</code><br> <code>if (oneRect.origin.x+oneRect.size.width &gt; size.width) {</code><br> <code>oneRect.origin.x = startingRect.origin.x;</code><br> <code>oneRect.origin.y -= 40;</code><br> <code>}</code><br> <code>rectArray[i] = oneRect;</code><br> <code>}</code><br> <code>[self draw];</code> </p> </blockquote> <p>in my draw method:</p> <blockquote> <p><code>glColor4f(1.0, 0, 0, 1.0);</code><br> <code>glLineWidth(1.0f);</code><br> <code>[self drawRectange:rec1];</code> </p> </blockquote> <p>and in my drawRectangle method:</p> <blockquote> <p><code>glColor4f(1.0, 0.0, 0.0, 1.0);</code><br> <code>CGPoint vertices[4] = {</code><br> <code>ccp(rect.origin.x, rect.origin.y),</code><br> <code>ccp(rect.origin.x+rect.size.width, rect.origin.y),</code><br> <code>ccp(rect.origin.x+rect.size.width, rect.origin.y+rect.size.height),</code><br> <code>ccp(rect.origin.x, rect.origin.y+rect.size.height)</code><br> <code>};</code><br> <code>ccDrawPoly(vertices, 4, YES);</code><br> <code>glVertexPointer(2, GL_FLOAT, 0, vertices);</code><br> <code>CC_ENABLE_DEFAULT_GL_STATES();</code> </p> </blockquote> <p>The problem is, since the draw method overrides the original (at least thats what i think it does), i can't modify it to accept a CGRect parameter so it can send a message to the drawRentangle method for each rect. Can someone please help me? Many thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload