Note that there are some explanatory texts on larger screens.

plurals
  1. POSelectors in Cocos2d schedule method
    text
    copied!<p>So I am doing this to initialize my selector: </p> <pre><code>//In .h SEL selectors[3]; //In .m selectors[0] = @selector(rotate); selectors[1] = @selector(discharge); </code></pre> <p>And here is the problem:</p> <p>When I call this in my init method in Cocos2d like this:</p> <pre><code>[self performSelector:selectors[0]]; </code></pre> <p>it works fine, but when I call this line of code in a method called moveThings which is invoked through the schedule (<code>[self schedule:@selector(moveThings:)]</code>) at the end of my init method in Cocos2d it gives <code>EXC_BAD_ACCESS</code>. What is the problem with scheduling things?</p> <p>UPDATE:</p> <p>I have found there is a problem with the rotate function (the function being stored in selector[0]). Here it is:</p> <pre><code>-(void)rotate:(ccTime)delta { if (((CCSprite *)[creature objectAtIndex:0]).rotation &lt; 360) { ((CCSprite *)[creature objectAtIndex:0]).rotation++; } else { ((CCSprite *)[creature objectAtIndex:0]).rotation++; } } </code></pre> <p>If I comment the contents of the method out it works fine when called through moveThings and init.</p> <p>If I change the methods contents with:</p> <pre><code>((CCSprite *)[creature objectAtIndex:0]).rotation++; </code></pre> <p>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.</p> <p>Further update:</p> <p>If I call:</p> <pre><code>((CCSprite *)[creature objectAtIndex:0]).rotation++; </code></pre> <p>In moveThings (which is being, as I've said before, invoked by the <code>schedule:(SEL)</code> method) it fails. Where as long as it is not invoked through a method that is the called by schedule it works.</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