Evening all,
I created a generic method to handle execute tweens for lots of objects, rather than having to write out all the tween code each time. This has worked fine for weeks but i'm not using this everywhere in my game yet so there may be issues I haven't run into.
-(void) animateObject:(SPDisplayObject*)targetObj property:(NSString *)pstring targetLoc:(int)tvalue duration:(float)time tweenType:(NSString*)transition { [self.stage.juggler removeTweensWithTarget:targetObj]; SPTween *myTween = [SPTween tweenWithTarget:targetObj time:time transition:transition]; [myTween animateProperty:pstring targetValue:tvalue]; [self.stage.juggler addObject:myTween]; }
Using this I can call, for example:
[self animateObject:mainMenuSpider property:@"y" targetLoc:220 duration:2.0f tweenType:SP_TRANSITION_EASE_OUT_BOUNCE];
I am now finding that I need to be able to chain tweens or atleast know when the tween has finished.
I didn't want use TWEEN_COMPLETED methods as i'm not sure how I would get a message back to the method that calls it that the tween has completed when I may not be aware of the tween at that level. I suppose I could bubble up a message but i'm trying to keep this contained in a single method (I might move it to it's own class if it needs to be any more complex). So instead I tried passing a delay parameter, however this crashes with an invalidException:
-(void) animateObject:(SPDisplayObject*)targetObj property:(NSString *)pstring targetLoc:(int)tvalue duration:(float)time tweenType:(NSString*)transition tweenDelay:(float)delay { [self.stage.juggler removeTweensWithTarget:targetObj]; SPTween *myTween = [SPTween tweenWithTarget:targetObj time:time transition:transition]; myTween.delay = delay; [myTween animateProperty:pstring targetValue:tvalue]; [self.stage.juggler addObject:myTween]; }
I'm not sure why, however I would like to know if this kind of approach is even possible? Thanks