Move sprite along path - ios

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 :)

Related

I need help to draw an icosahedron 3D object in an UIKit app

Although I am quite experienced with most frameworks in iOS, I have no clue when it comes to 3D modelling. I even worked with SpriteKit, but never with something like SceneKit.
Now a customer wants a very ambitious menu involving a 3D object, an 'icosahedron' to be exact. I want it to look something like this:
So I just want to draw the lines, and grey out the 'see-through' lines on the back. Eventually I want the user to be able to freely rotate the object in 3D.
I already found this question with an example project attached, but this just draws a simple cube: Stroke Width with a SceneKit line primitive type
I have no clue how to approach a more complex shape.
Any help in the right direction would be appreciated! I don't even need to use SceneKit, but it seemed like the best approach to me. Any other suggestions are welcome.
to build an icosahedron you can use SCNSphere and set its geodesic property to YES.
Using shader modifiers to draw the wireframe (as described in Stroke Width with a SceneKit line primitive type) is a good idea.
But in your case lines are not always plain or dotted — it depends on the orientation of the icosahedron. To solve that you can rely on gl_FrontFacing to determine whether the edge belongs to a front-facing or back-facing triangle.

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.

Drawing lines in cocos2d

I'm trying to draw lines in Cocos2d using touches.
I had a system where it would just add a small sprite where you touched, but it's working terribly. So I've been trying to find a way to draw actual lines using a method like ccDrawLine, but every tutorial I find seems to leave out something, and I just can't figure it out.
I've found this tutorial, Drawing line on touches moved in COCOS2D but I don't understand a few things about that.
It seems to reference the same variable from two different files, so I don't understand how it's doing that. (The naughtyTouchArray variable)
I can't find a complete guide on drawing lines, so sorry for the codeless question, but I'm getting frustrated.
Thanks.
The answer you've linked in your question provides good solution to your problem. There is no "two different files". Just two different methods of one layer. One method (ccTouchesMoved:withEvent:) handles touches and fill the array of points to be connected to each other one-by-one with lines. From cocos2d documentation, all drawing must be placed in the draw method of the node. So, another (draw) method just draws lines according to the given array. Cocos2d is based on OpenGL and it fully redraws scene every tick, so you cannot just draw new line. You had to draw all of them.
Or any other node can draw your array in it's draw method, so you can simply pass stored array of points from the layer, that detects touches, to this node.

Making a Drawable layer in cocos2d

I want to make sort of a chalk board for part of my app, and I was wondering how to accomplish this?
I was thinking I could create a sprite and have it's image set to something very small (maybe a small point), and then add a new instance of that sprite everywhere the user touches to simulate a draw event. Something like [self addChild:someSprite]; for each touch location.
But it seems like that would be extremely memory inefficient. There has to be a better way than that, Maybe drawing actual lines? I'm probably overlooking some method.
Thanks for any help.
You need to use CCRenderTexture for chalk board paintings. Check this article & project for a drawing example.
Your variant isn't such "memory inefficient" as you think. No matter how much sprites will you create with the same texture, your texture will be placed to the memory only once. And all the sprites will use pointer to it. Just one thing to prevent many unnessesary calls is to use CCBatchNode. It will draw all it's children with single draw call. Without using it, draw will be called on every children.

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