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

  • SEARCH
  • Home
  • 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 542269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:25:44+00:00 2026-05-13T10:25:44+00:00

I am new to Objective-C and iPhone development in general. I am using the

  • 0

I am new to Objective-C and iPhone development in general. I am using the Cocos2d-iphone library for a game engine in an attempt to develop a very simple game.

I have been following a few tutorials to get the hang of things and am attempting to put together a very simple “level” where some balls bounce around the screen using the Chipmunk physics engine. Below is the definition and implementation of the file causing the problems. The warning generated during compilation is:

GameScene.m:69: warning: ‘GameLayer’ may not respond to ‘-addChild:z:’

GDB also provides the following:

Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘*** -[GameLayer addChild:z:]: unrecognized selector sent to instance 0xf6ff90’

If I comment out this line the program will no longer crash when a GameLayer is called. (Commented the line in question with “<< Apparently . . . error?”. It’s near the bottom of GameScene.m – The second bit of code in my post.)

// GameScene.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "chipmunk.h"

@interface GameScene : Scene
{
}
@end

@interface GameLayer : Layer
{
    cpSpace *space;
}

-(void) makeBall: (float) x y:(float)y;
-(void) setupGame;

@end

And then the implementation:

// GameScene.m
#import "MenuScene.h"
#import "GameScene.h"

void updateShape(void* ptr, void* unused){
    cpShape* shape = (cpShape*)ptr;
    Sprite* sprite = shape->data;
    if(sprite){
        cpBody* body = shape->body;
        [sprite setPosition:cpv(body->p.x, body->p.y)];
    }
}

@implementation GameScene
- (id) init {
    self = [super init];
    if (self != nil) {
        Sprite * bg = [Sprite spriteWithFile:@"background.png"];
        [bg setPosition:cpv(240, 160)];
        [self add:bg z:0];
        [self add:[GameLayer node] z:1];
    }
    return self;
}
@end

@implementation GameLayer
- (id) init {
    self = [super init];

    if(self != nil) {
        isTouchEnabled = YES;
    }

    //Make it shoot:
    isTouchEnabled = YES;

    //Initialize Chipmunk:
    cpInitChipmunk();

    // Create the chipmunk space
    space = cpSpaceNew();
    cpSpaceResizeStaticHash(space, 400.0f, 40);
    cpSpaceResizeActiveHash(space, 100, 600);

    space->gravity = cpv(0, -400);
    space->elasticIterations = space->iterations;

    // Update Chipmunk
    // Calls the "tick" function below. This function subsequently
    // makes a call to the update function which updates all of the 
    // sprites on the screen.
    [self schedule: @selector(tick:) interval: 1.0f/60.0f];

    // Setup the game (place the player and balls on the screen)
    [self makeBall:100 y:100];

    return self;
}

// Sets up the game, placing the balls on the stage. Also creates the
// flor boundries and player
-(void) setupGame {
}

// Creates a ball and adds it to the desired location on the screen
-(void) makeBall: (float) x y:(float)y {
    Sprite *ball = [[Sprite spriteWithFile:@"start_ball.png"] retain];
    ball.position = cpv(x,y);
    [self addChild:ball z:2]; << Apparently this line is causing the error?
}

-(void)tick: (ccTime)dt {
    cpSpaceStep(space, 1.0f/60.0f);
    //cpSpaceHashEach(space->activeShapes, &updateShape, nil);
}

@end

I’ve commented the line in the code above that I believe is causing the error. (<< Apparently this line . . .).

I’m sure it’s something idiotic, but any help would be appreciated!

Thanks 🙂

  • 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-13T10:25:44+00:00Added an answer on May 13, 2026 at 10:25 am

    The compile-time warning is because the @interface part does not have anything called - addChild:z:.

    The runtime error is because the @implementation part does not have - addChild:z:.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to Objective-C and iPhone development and have been using Apress' Beginning iPhone
I'm pretty new to objective-C (and C in general) and iPhone development and am
I am new to Objective C and iPhone development. I am using CoreData on
I am new to Objective-C and iPhone I have to sort a NSDictionary using
I am new to objective C and iPhone game development. I am having some
I am new to iPhone development. I have created the database using the terminal
I am new in iPhone development and Objective-C. I have RootViewController and DetailViewController. I
I am new to objective-c and started iphone application development. I have noticed the
I'm pretty new to Objective C and iPhone development and have hit a problem
I am new to iPhone development and Objective C. I have decided I would

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.