swift animate spritekit with damping effect - ios

I've been searching on the internet for several days, I didn't find what I'm looking for.
I'm working on an iOS game and I would like to move some sprites using usingSpringWithDamping (to have some rubber effect when moving my sprites).
I have found many solutions for UIViews but nothing for SKSpriteNode.
I would like to move a SKSpriteNode from position 1 to position 2 with a Damping effect.
Can you please give me some ideas?
Thanks.
C.C.

The Sprite Kit Utils from Ray Wenderlich (https://github.com/raywenderlich/SKTUtils) could be what you are looking for. Specifically, using SKTEffects and SKTTimingFunctions will allow you to add easing to your SKActions.
For example SKTTimingFunctionElasticEaseIn, SKTTimingFunctionElasticEaseOut, and SKTTimingFunctionElasticEaseInOut have the rubber effect you are looking for, but you may need to tweak them to your needs. Ray's utils also have other easing functions available; there is a good reference on different easing functions at: http://easings.net
Hope this helps!

UIView animations have support for spring animations, but these are not available in SpriteKit.
There is a third-party library on GitHub which extends SKAction with spring animations: https://github.com/ataugeron/SpriteKit-Spring

Related

Move SKCameraNode using LERP through SKConstraint

I was just wondering if there is a way to implement a linear interpolation effect on my SKCameraNode while it is following my player node through use of SKConstraints. I am currently using constraints identical to the constraints used in Apple's Demo Bots tutorial. The alternative seems to be either using actions to reposition my camera with a delay/time, or changing the position with a delay directly in the update method. The camera scrolling as it is seems kind of jerky while the distance constraint to the player is set to a constant 0.0 like it is in Demo Bots. Please let me know your thoughts and all feedback is appreciated.

Move sprite along path

I'm working with SpriteKit and wondering if anyone knows how to make a sprite follow a path. I've seen other questions online that talk about moving a sprite along a CGPath, but how would you do it if the path is another sprite?
Video example
Have a look at Is there a way to create a CGPath matching outline of a SKSpriteNode? - it seems from that answer that the problem is much more complex than it first appears.
If your sprite is an SVG, a simpler solution may be to manually convert the SVG into a CGPath, and then using that CGPath in your game. A simple tool for doing that is available here: https://swiftvg.mike-engel.com/. Of course doing this manually won't scale well if you have many different sprites.
This may not be exactly the answer you are looking for, but it seems right now there is no simple way to accomplish what you need :)

Dynamic Bezier drawing in a spritekit game - Best (performance) approach?

I am not an iOS developer, I just started to implement my game, that I have done in flash, hoping that it will be super fast using the native environment.
The project is a 2d game that has a lot of dynamic bezier drawing based on the user's interaction. Basically I draw dynamic blobs (amoeba type of shapes).
First I tried Swift, which is very similar to actionscript, but it turned out, Apple won't be able to accept apps built with Swift before the final release of Xcode6 and as I want release my game before September I went to objective C route.
I wanted to use sprite kit because of the integrated physics engine, sprite hierarchy, etc.
I tried to use SKSphapeNode for drawing, but I realised it very quickly, it is not suitable for my needs. (cannot draw a stroke if it is thicker than 2 pixels, it has memory leaks etc.)
So I used UIBezierPath that I put into an UIImage, but I am not happy with the performance as I have to create a new UIImage with the new dynamically generated bezier shape.
These are the options I found so far:
SkShapeNode - not suitable for my game
UIBezierPath - UIImage > I have to create a new UIImage every frame, so it is slow
OpenGL - I haven't tried it yet, I am not sure it is possible to use it with Sprite kit
CALayer - I am trying to integrate it with spritekit at the moment, but I have a feeling I will have the same problem that I had with the UIImage approach.
Does anybody have any idea, tip what approach would be the best performance-wise?
Thank you for your help in advance!
I tried to create a lightning effect with using SpriteKit, so check out my article about that: https://andreygordeev.com/2014/11/01/lightning-with-srite-kit.html
Some of the approaches use UIBezierPath, so may be you find that useful.

SpriteKit SKAction easing

Well the title gives the question away, how can I apply easing to the SKAction node actions in SpriteKit?
I found that this works:
SKAction *moveAction = [SKAction moveByX:moveX y:moveY duration:0.5];
moveAction.timingMode = SKActionTimingEaseInEaseOut;
[node runAction:moveAction];
However there are only a few easing types available there, namely Linear, EaseIn, EaseOut, EaseInOut.
And those easing values are fixed and cannot be altered. I am looking for something like EleasticInOut. With preferably a bit more control. How can I create that?
I've been using the SKEase framework:
https://github.com/buddingmonkey/SpriteKit-Easing
It's as simple to use as the standard SpriteKit Actions and adds all the usual more complex eases, cubic, bounce, elastic, back etc.
SpriteKitUtils also adds more complex easing types and some handy SpriteKit utilities: https://github.com/raywenderlich/SKTUtils
The other option is to roll your own using the custom action method, and pass it a block of code with your custom easing/animation function:
-(SKAction *)customActionWithDuration:(NSTimeInterval)seconds actionBlock:(void (^)(SKNode *node, CGFloat elapsedTime))block
Apple introduced spring animations in UIKit a couple years ago, by letting you set a spring damping and initial velocity when performing a UIView animation. Unfortunately they didn't implement that in SpriteKit, so I made my own library that does just that.
It's a set of extensions on SKAction that replicate most factory methods, adding the damping and velocity parameters.
The code is on GitHub, feel free to use it: https://github.com/ataugeron/SpriteKit-Spring
Here is fresh, as spring water, answer goes. In iOS 8 timingFunction was introduced. It allows you to create custom timing curves.
The return SKActionTimingFunction value of the timing function
determines the actual time used to perform the animation.
This way, you can implement your own easing function. Although it has certain limitations: output values must be between 0.0 and 1.0. So for more realistic elastic bouncing I would recommend use SpriteKit-Spring

Exploding Ring particle effect with Cocos2d

I found the Exploding Ring particle effect best suite what I need but I could not figure out how to control the blast radius of this particle effect. I.e: not exploding out the whole screen but only exploding in a small circle
Does anyone know how to do it?
Thanks in advance
Probably easiest method is to use Particle Designer (http://particledesigner.71squared.com/). It has full Cocos2D support and you can visually see what you want with the editor without having to code it. You can see how to integrate the export files at http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:particles?s[]=particle. Hope that helps!

Resources