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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:31:03+00:00 2026-05-23T07:31:03+00:00

So I am doing this to initialize my selector: //In .h SEL selectors[3]; //In

  • 0

So I am doing this to initialize my selector:

//In .h

SEL selectors[3];

//In .m

selectors[0] = @selector(rotate);
selectors[1] = @selector(discharge);

And here is the problem:

When I call this in my init method in Cocos2d like this:

[self performSelector:selectors[0]];

it works fine, but when I call this line of code in a method called moveThings which is invoked through the schedule ([self schedule:@selector(moveThings:)]) at the end of my init method in Cocos2d it gives EXC_BAD_ACCESS. What is the problem with scheduling things?

UPDATE:

I have found there is a problem with the rotate function (the function being stored in selector[0]). Here it is:

-(void)rotate:(ccTime)delta {
    if (((CCSprite *)[creature objectAtIndex:0]).rotation < 360) {
        ((CCSprite *)[creature objectAtIndex:0]).rotation++;
    }
    else {
        ((CCSprite *)[creature objectAtIndex:0]).rotation++;
    }
}

If I comment the contents of the method out it works fine when called through moveThings and init.

If I change the methods contents with:

((CCSprite *)[creature objectAtIndex:0]).rotation++;

It fails… But, again, I would like to state that all of these things do work if I call it in my init method, even call it twice in a row, but it will not work (except when I take out the contents of the rotate method) if I call it through the moveThings: method which is being invoke through the schedule method it fails.

Further update:

If I call:

((CCSprite *)[creature objectAtIndex:0]).rotation++;

In moveThings (which is being, as I’ve said before, invoked by the schedule:(SEL) method) it fails. Where as long as it is not invoked through a method that is the called by schedule it works.

  • 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-23T07:31:03+00:00Added an answer on May 23, 2026 at 7:31 am

    The problem is that when you call performSelector there are only two options:

    1. have your selector take no arguments and leave the “:” off the @selector(foo) definition.
    2. have your selector take either one or two arguments which both must be an NSObject or subclass

    it is the latter that is messing you up here I suspect.

    Here are the three forms of performSelector:

    - (id)performSelector:(SEL)aSelector;
    - (id)performSelector:(SEL)aSelector withObject:(id)object;
    - (id)performSelector:(SEL)aSelector withObject:(id)object1 withObject:(id)object2;
    

    You’ll note that the withObject arguments are all of type id which is an Objective C object.

    The selector you’re trying to use takes a ccTime which is a float and not an Objective C object as it’s param and that is why things are crashing:

    -(void)rotate:(ccTime)delta;
    

    One option is to make a wrapper method that takes a wrapped ccTime and unwraps it and calls the rotate:(ccTime) method:

    - (void) wrappedRotate: (NSNumber*) inDelta
    {
        [self rotate: [inDelta floatValue]];
    }
    

    then use

    selectors[0] = @selector(wrappedRotate:);
    

    and then call via:

    [self schedule: @selector(moveThings:)]);  // cocos2d schedule
    
    ... 
    
    - (void) moveThings: (ccTime) dt
    {
       [self performSelector: selectors[0] withObject: [NSNumber numberWithFloat: dt]];
      ...
    }
    

    One reason you are getting confused is because Cocos2d is using @selector in somewhat more complicated ways (see CCScheduler.m in the CCTimer::initWithTarget:selector:interval: and CCTimer::update: method in particular).

    disclaimer: code typed into SO so not checked with a compiler, but the essence of what you need should be here.

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

Sidebar

Related Questions

I have a collection in backbone... in the initialize method I'm doing this.... I
I've got a strange problem here. I have a class that I'll call MainView
Im doing this project where i need to download files through a webservice (images,
I have some code doing this : var changes = document.getElementsByName(from); for (var c=0;
I'm doing this system Stacked and I am creating the search function. And in
So I'm doing this in PHP but it is a logic issue so I'll
I'm probably doing this all wrong. I have a text file full of data
As I am currently doing this project in only C, I've up untill this
any problems with doing this? int i = new StreamReader(file.txt).ReadToEnd().Split(new char[] {'\n'}).Length
I find myself doing this repeatedy. $jq(button).filter(function(){ return this.id.match(/^user_(\d+)_edit$/); }).click(function(){ var matches = this.id.match(/^user_(\d+)_edit$/);

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.