I have a
- (void) removeStuff : (int) i
{
}
CallFunc doesn't seem to recognize removeStuff i:8 ......
is this not possible ?
A fast, easy to use, free, and community supported 2D game engine
I have a
- (void) removeStuff : (int) i
{
}
CallFunc doesn't seem to recognize removeStuff i:8 ......
is this not possible ?
CallFunc doesnt work that way. Try CallFuncND with a pointer to your int.
And since it is an int, and the int types and pointer types have the same size, you can pass directly the int. Just cast it as a (void*).
See SpriteTest.m (r1159).
I've just improved the CallFunc test. Now, it also shows how to use CallFuncND and CallFuncN.
Yeah you need to use CallFuncND, but that requires that your method take an additional initial parameter that is the CocosNode that the action is being run on. (If you don't need that then you can just create a dummy parameter and ignore it.) So something like this:
- (void)removeStuff:(id)dummy atIndex:(int)i { ... }
and then you call it like
[someNode runAction:[CallFuncND actionWithTarget:yourObject selector:@selector(removeStuff:atIndex:) data:(void *)8]]
If I wanted to use CallFuncND on a method like this:
-(void) doSomethingWithScene:(Scene *) withEffect:(int)effectType;
Can a selector with two or more data objects be used? I think I understand most of the CallFuncND method, but not completely.
My test code (one variation):
[myCustomNode runAction:
[CallFuncND actionWithTarget:myNode selector:@selector(doSomethingWithScene:withEffect:)
data:[Director sharedDirector].runningScene, (void*)10], nil];@javy,
I do it like this (I couldn't find the original post here that helped me figure it out.. ):
NSMutableArray *prams = [[NSMutableArray alloc] initWithCapacity:2];
[prams addObject:[NSValue valueWithCGPoint: enemy.position] ];
[prams addObject:[NSValue valueWithCGPoint: enemysh->body->v] ];
id sgi = [CallFuncND actionWithTarget:game selector:@selector(spawnGameItemFromCallFuncND:data:) data:prams];
then, get the items from the array and call the real function..
- (void) spawnGameItemFromCallFuncND:(id) sender data:(void*)d
{
NSMutableArray *dta = (NSMutableArray*)d;
[self spawnGameItemAtPoint:[[dta objectAtIndex:0] CGPointValue] withVelocity:[[dta objectAtIndex:1] CGPointValue] ];
[dta release];
}
- (BOOL) spawnGameItemAtPoint: (CGPoint) spawnSpot withVelocity:(CGPoint) velocity
{
...
There is probably a be a better way, but this works for what I'm doing.
HTH,
Mark
Yes, that's very helpful. Multiple arguments would be nice, but I understand that any library has to have some limitations. I'm grateful for what we have as it is.
Thanks again.
It took me 30 minutes to figure out why my code was blowing up.
PLEASE, add comments to CallFuncND explaining that it calls a method with two arguments.
First is sender and second is the actual data.
I would rather change this two have 3 versions with 1 2 or 3 arguments and leave people decide what this arguments will be.
Assuming that I wand the sender is a restriction.
I am using 0.8.2 atm, I am not sure if in 0.99 there are better explanations.
You must log in to post.