I need to call a function after a CCSpeed delay so that I can change the speed dynamically. As far as I know, I can’t use a CCSpeed inside a CCSequence, so I tried using a CCSequence (CCDelayTime, CCCallFuncND, nil) inside a CCSpeed, which also doesn’t appear to work. Anyone have any suggestions?
In my BackgroundLayer class, I have a NSNumber *multiplierSpeed; :
@interface BackgroundLayer : CCLayer {
NSNumber *multiplierSpeed;
}
@property (nonatomic, retain) NSNumber *multiplierSpeed;
-(void)rotateWorldAndSwapIn:(id)sender data:(int)frame;
@end
And in my implementation:
@synthesize multiplierSpeed;
-(id)init {
self = [super init];
if (self != nil) {
//...
multiplierSpeed = [NSNumber numberWithFloat:1.0f];
CCSpeed *delay = [CCSpeed actionWithAction:[CCSequence actions:[CCDelayTime actionWithDuration:20],[CCCallFuncND actionWithTarget:self selector:@selector(rotateWorldAndSwapIn:data:) data:(void*)3], nil] speed:1.0f];
[delay setTag:10];
[self runAction:delay];
//...
}
}
-(void)rotateWorldAndSwapIn:(id)sender data:(int)frame {
CCLOG(@"test"); //This is fine
CCLOG(@"multiplierSpeed=%f",[multiplierSpeed floatValue]); //Crashes here
//...
}
I am getting this error:
EXC_BAD_ACCESS on callbackMethod_(targetCallback_,selector_,target_, data_);
in the CCActionInstant.m file.
Also, is it because CCSpeed wraps around CCCallFuncND, which has no delay, that’s throwing this error? If so, do you have any alternative suggestions?
Thanks for helping!
You need to use self.multiplierSpeed instead of only multiplierSpeed.
and then in the CCLOG,
Unless you use self.varName, Objective-c won’t be using the getter/setter methods, rather would try to access the instance variable directly causing a bad memory access (as no memory was allocated for that var)