I’d like to schedule a selector in a child node of the class GameScene without having to call the schedule method in the child node class (e.g. [self schedule etc..]).
Here is the code snippet I am calling in the GameScene class to call a method in the child class that handles the background of my GameScene.
ParallaxMultipleBackgrounds *background = [self getChildByTag:GameSceneBackgroundBase];
//I TRIED THIS:
[background schedule:@selector(([background changeSpeedFactorBy:3])) interval:1];
//AND
[background schedule:@selector(changeSpeedFactorBy:3)];
//AND
[[background schedule:@selector(changeSpeedFactorBy:3) interval:1] ];
//BUT..
Unfortunately none of those methods call works as I get various error message from the compiler. I am not sure how what I am doing wrong because I declared the selector -(void) changeSpeedFactorBy:(float)factor in the ParallaxMultipleBackgrounds class.
Any help?
You cannot give an argument to the selector.
The easiest way to do that is to have an iVar in the
ParallaxMultipleBackgroundsclass like this: int modifier. Make it areadwrite property.Then assign it and call the schedule method.
Like this :
And in the
changeSpeedFactorBymethod make the change by using that modifier variable.Hope this helps.
Cheers!
EDIT: You can also send a parameter by sing CCCallFuncND. And if you then declare a CCRepeatForever action you can indeed call a selector forever with a param.
Like this:
Sorry for any syntax errors , I’m not on a Mac right now. But that would be a whole idea. One mention though , when you sent that data argument , it’s a void* . So you won’t be able to send an integer there , but you can with a NSString.