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 9115015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:19:53+00:00 2026-06-17T04:19:53+00:00

so i was programming a game in Xcode 3.2.4 with cocos2d and i made

  • 0

so i was programming a game in Xcode 3.2.4 with cocos2d and i made a class named player. as of now it only has the one function that does nothing.

#import <Foundation/Foundation.h>
#import "cocos2d.h"

@interface Player : CCSprite {

}

-(void)leftButtonPressed;

@end 



#import "Player.h"


@implementation Player

- (id)init{
    if((self=[super init])){
        self = [CCSprite spriteWithFile:@"playerPlane.png"];
        }
    return self;
}

-(void)leftButtonPressed{
}

@end `

whenever i try to call leftButtonPressed from anywhere, the entire app crashes with this in the console

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CCSprite leftButtonPressed]: unrecognized selector sent to instance 0x6e4bb50'

i initialize the Player as an instance in another class by doing
Player * thePlayer = [[Player alloc]init];

please help! 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-06-17T04:19:54+00:00Added an answer on June 17, 2026 at 4:19 am

    This causes the problem:

    - (id)init{
        if((self=[super init])){
            self = [CCSprite spriteWithFile:@"playerPlane.png"];
            }
        return self;
    }
    

    What are you doing? You initialise the newly created (the caller that calls alloc/init created it) Player object. The init method may even have returned another instance than the one that is currently executing (some strange unique cocoa thing). And when that was successful then you crate a new CCSprite object and assign it to self. Self is then returned to the caller.
    (If you would not ARC – I assume you do – then this for sure would create a memory leak);

    But the caller expects to deal with a Player object and later sends the leftButtonPressed message to it which the CCSprite cannot respond to.

    That is, what the error message tells you.

    You may use instead:

    - (id)initSpriteWithFile(NSString*)fileName{
        if((self=[super initSpriteWithFile:fileName])){
            // Do any additional setup here. If you don't have any setup then do not overwrit the init method at all. 
            }
        return self;
    }
    

    or something like:

    - (id)init{
        if((self=[super init])){
            [self setFileName:@"playerPlane.png"]; //This method may not exist at all but you may find an appropriate one in the docs. I am not used to CCSprit. I am just trying to explain the concept by example. 
            }
        return self;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm programming a game engine right now. The hardest part for me has been
For a multi-player programming game, I'm working on a background compilation server for Scala
LATER EDIT: Please mention not only game programming books, but also more scientific/simulation oriented
I'm programming a game which sends the position of the player to the server
Is it possible for kids with only HTML/CSS programming experience to do game programming
So it has been a while since I have done any game programming in
I'm programming a game applet that saves data to a CSV file and got
I'm newbie to java game programming and till now was building games using jquery
I'm making a programming game where the player can program their allies' behavior. The
For an open-source multiplayer programming game written in Scala that loads players' bot code

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.