Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I slow down a SKSpriteNode that is running SKAction followPath for a slow motion effect using Sprite Kit?

I basically want the action to be running and then in the middle of the action create a slow motion effect and then later bring it out of slow motion. Does anyone have any good feedback of how this might be done? I've thought about creating the action manually and using an update method, but I feel like that might be overkill. I was hoping for a simpler solution.

The other thought I have is to stop the action and then start it again at a slower duration, but I don't think it will stay on the same path and it will probably look weird.

This is the code I'm using to create the action.

CGMutablePathRef cgpath = CGPathCreateMutable();
CGPathMoveToPoint(cgpath,NULL, mysprite.position.x, mysprite.position.y);
CGPathAddCurveToPoint(cgpath, NULL, cp1.x, cp1.y, cp2.x, cp2.y, e.x, e.y);
[mysprite runAction:[SKAction sequence:@[[SKAction followPath:cgpath asOffset:NO orientToPath:YES duration:3]]]];
CGPathRelease(cgpath);
like image 293
brilliantairic Avatar asked Dec 10 '13 22:12

brilliantairic


1 Answers

Each node has a speed property:

A speed modifier applied to all actions executed by a node and its descendants.

Discussion
The default value is 1.0, which means that all actions run at their normal speed. If you set a different speed, time appears to run faster or slower for all actions executed on the node and its descendants. For example, if you set a speed value of 2.0, actions run twice as fast.

You could set this to a value smaller than 1 to make the action run slower. You can even animate the speed to gradually slow down:

[mySprite runAction:[SKAction speedTo:0.5 duration:1.0]];
like image 127
DrummerB Avatar answered Oct 20 '22 16:10

DrummerB