Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7547405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:26:42+00:00 2026-05-30T09:26:42+00:00

So I’m trying to draw a simple rectangle in my iOS cocos2d game, but

  • 0

So I’m trying to draw a simple rectangle in my iOS cocos2d game, but it’s simply not showing up. At first, I added my rectangle drawing code to my Main scene’s init method, but it wasn’t showing up, so I looked around.

I read this http://www.cocos2d-iphone.org/forum/topic/655 and what I got from it, was to make a new class, extend the CCLayer class, and add it to my main scene.

This is my Main scene’s code:

+(CCScene *) scene
{
    // 'scene' is an autorelease object.
    CCScene *scene = [CCScene node];

    // 'layer' is an autorelease object.
    HelloWorldLayer *layer = [HelloWorldLayer node];
    RectLayer *rectLayer = [RectLayer node];
    // add layer as a child to scene
    [scene addChild:rectLayer];
    [scene addChild: layer];

    // return the scene
    return scene;
}

And this is my RectLayer.m code,

#import "RectLayer.h"

@implementation RectLayer

-(id) init {
    if( (self=[super init] )) {
        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);
    }
}
@end

Now I’m getting a EXC_BAD_ACCESS error when trying to open it with the iPad simulator.

I’ve recently just started Objective-C, so I’m not quite sure what’s wrong.

Thanks for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T09:26:43+00:00Added an answer on May 30, 2026 at 9:26 am

    Put the drawing code in the method draw:

    - (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);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.