How to enforce touching within a ring shape using iOS SpriteKit? - ios

I need to have the player moving the finger within the shaded ring:
The program should be able to detect "out of boundary" events once the finger moves outside the ring (shown in red).
Any best practices for doing this in SpriteKit, ideally in Swift? Thanks!

You could draw your shapes using CGPath, then use CGPathContainsPoint to determine if the touched locations are inside or outside the path.
You can use CGPaths like this in SpriteKit using SKShapeNode.

Related

iOS: move circle shape view by collision by dragging another?

I have two UIViews shaped like a circle. (see image).
I am trying to figure out how to make the two views move by collision.
So I am moving one with a touch by changing it's position as I move my finger on it. I want to see the other move as I "push" the one I am moving against the other circle shaped view.
What is the correct way to achieve this?
Using SceneKit did the trick. I created the geometries and then applied physic bodies to each. With the proper physics configuration in the scene they now collide.

More precisse shape or mask for a SKSpriteNode object

I'm bulding a simple application using SpriteKit for iOS 7 / 8 but I'm having some issues with my sprites when I try to touch and launch some events from one of two nodes that are too close to each other.
When I try to touch one of them, I end up touching the upper layer one square mask, and if I change the [self addChaild:] order it happens the same but with the other one.
I want to know if I can create a more precisse mask for my nodes so this won happen when I try to touch them. I know I can create a physics world and a physics body for each of them to control Collision Detection but I don't know if this is the right approach.
BTW... I'm using the methods touchesBegan:withEvent: and touchesEnded:withEvent: for touching events detection.
PD: if you need any more info about my implementation please let me know.

SpriteKit Racing top down Game

I want to write a simple top down racing game for iOS. I want to use Sprite Kit instead Cocos2D , I'm new to game development and I have a question:
How can I create the race tracks? What I think is: One single big background image for each track and a car that moves over it and remains inside the track by interaction with a path. The path is inserted by a coordinate system in the level code and represents the "borders" of the road.
Is this a good way to start a top down racing game? Or are there better ways? How can I "draw" the path over my background image?
You can use "Tiled Map Editor" http://www.mapeditor.org/ to create your maps. I'm thinking you'll only need a few unique tiles, one for straight track, one for grass, one for curved track, maybe some trees, etc.
As for the path, you can try to use an polygonal edge physics body? And then move the car to where the user touches on the screen. if the user tries to move the car outside, the car will bump against the physics body of the edge.

how to extract more touch points from UIResponder?

When I touch a UIView with the base of my finger tip, and get the touch point using touches anyObject, I get a single touch point, even though the base of my finger tip has an area that touches a lot many points. Is there a way to get all those points? If there is no such way, how are simple paint apps implemented in ios?
You are getting the only point / touch. Each touch is related to a single finger. This is controlled by iOS.
'Simple' drawing / painting apps use the path traced by the touch points together with the current line drawing width and texture to create lines or bezier paths.
If you're trying to create a drawing app with some form of pressure sensitivity then you'd need to integrate with a 3rd party stylus (like this one)

Animating sprites on top of mapview (iOS)

I am developing an application which will show where trains are at any given time. It will receive gpx-data from the trains to get their location.
Is there any way to animate a sprite moving along a restricted line in a mapview? In my example, a train moving along a trainroute.
I have drawn the trainroutes as polyline in an overlay, and the train is an annotation.
I ended up making a visible overlay, then making a separate array out of the same coordinates.
To simulate the movement, the MKAnnotations uses 'setCoordinate' while iterating the array, which in fact is the same as the overlay.
This made the annotations look like they moved atop of a restricted overlay.

Resources