user3876107 user3876107 - 1 year ago 90
iOS Question

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:

  1. SkShapeNode - not suitable for my game

  2. UIBezierPath - UIImage > I have to create a new UIImage every frame, so it is slow

  3. OpenGL - I haven't tried it yet, I am not sure it is possible to use it with Sprite kit

  4. 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!

Answer Source

I tried to create a lightning effect with using SpriteKit, so check out my article about that:

Some of the approaches use UIBezierPath, so may be you find that useful.