SKAction launch method with argument?
I am trying to run SKAction *action = [SKAction performSelector:(SEL) onTarget:(id)];
and pass in a selector, which is a method that takes one argument. However, Xcode will allow me to insert performSelector:@selector(placeCoin:)
, but it will not allow me to pass the CGPoint argument to the selector. How am I supposed to do this? Should I seriously run it with the SKAction runBlock statement? It looks like there must be a way to do this.
This question is a little outdated, but I found an easy way to do it.
First create your action (in my case, I need an action that repeats forever):
-(void)MyAction
{
SKAction *wait = [SKAction waitForDuration: 0.01];
SKAction *performSelector = [SKAction performSelector:@selector(myMethod1) onTarget:self];
SKAction *sequence = [SKAction sequence:@[performSelector, wait]];
SKAction *repeat = [SKAction repeatActionForever: sequence];
}
Then create myMethod1 and run the required method with arguments:
-(void)myMethod1
{
[self myMethod2Arg1:something1 Arg2:something2 Arg3:something3];
}
Now all you have to do is launch an action on anything, and the method with arguments will be launched.
source to share