Moving around the planet in sprite kit - ios

I'm currently making a game where driving a moon lander across the terrain of alien planets. The lander is free moving so you can turn any direction you like.
I've got a camera centred on the player's vehicle and navigation is working well, however...
As the player approaches the horisontal sides (x) of the map I'd like the map to display continuously.
I've used a couple of different approaches so far; I've added an identical sprite as the map to the left of the map and created a method that moves the extended map to the right side if you approach that side instead, and I've also tested with two different extended maps, one for left and one for right. I've then setup physics for the extended maps and changed the landers position from one side of the map to the other as it collides with the extended maps.
My issue is that I'd like to have my enemies spawning and walking around the main map and as you approach the side you will of course not see the enemies on the other side of the map - you'd only see the extended map with no contents.
My preference would be for the world to "bend" so that as you approach the left edge you'd automatically see the right edge and vice versa. I have no idea whether this is even feasible so any suggestions are much appreciated.
Thanks in advance.

I'm not sure I understand your question. Maybe this will further discussion, anyhow.
If you are looking for a scrolling behavior then I would have two backgrounds (or more if you want a wider scrolling field) and your method for swapping the tiles around to make the background feel continuous, use the "camera" tracking technique and shown in Apple's sprite kit demo to follow your player (which it sounds like you are doing). Then when aliens move offscreen in either direction relocate them in the same way that you would swap out your background tile(s) with something like position.x += widthOfBackgroundTile.

Related

Select AR placed objects with a dot in the middle of the screen in Unity

I have seen numerous AR application behaving like this: there is a dot in the middle of the screen and we can position that dot on some objects and some content is displayed (I attacked an image if i was not clear enough). My question is how is this kind of behaviour obtained in Unity, my guess is that from that point you cast a ray, but I don't think that AR placed objects, from an ADF for example, can be found with the hit from that ray. The dot selecting objects placed on AR
I have made it work, with the aid of the Google Tango's Area Learning demo scene. I've placed some objects in the area and I have started to send a Raycast from the middle of the camera with "ViewportPointToRay" method. When that Ray would collide with a GameObject you can implement whatever functionality you need.

Draw circle and drag touch around SKSpriteNode

I am making a Sprite Kit game where the player (basically a stickman) has a running animation and a parallax scrolling background.
Now I have enemies that come near my player. To destroy these enemies sometimes I have to touch the enemies node to launch a rocket or attack them with an attack button or just jump over them.
Everything is working fine, but I want to add some extra moves to destroy them. I want some enemies that you can just destroy if you have drawn a whole circle around them. So imagine they come and you make a circle and then my player launch a laser or something. The problem is I have no idea where to start.
I haven't found anything on the internet. If it's too complicated or almost impossible how about touching my player node and dragging to the enemy?
EDIT: I think I have to create a custom GestureRecognizer that recognizes if a circle is drawn around a sprite and then runs the code. I don't know how this works ?
Yes, it's too complex. Not just from a coding point of view, but also from that of the player's experience.
Anything that requires complex gestures over a large amount of glass is annoying for the player because they're never going to have the same experience. Their finger's moisture and oil content always changes, as does the ambient temperature and cleanliness of their screen.
So big gestures required to be performed quickly (a gaming input like this) will sometimes be fun and smooth, and other times degrade as an experience based on the nature of the above properties.
Best to avoid them for a game's best possible experience.
If you must do it, there's two ways to research how.
Seek out "custom gesture" creation and utilisation through documentation and google, etc.
Think about using some kind of array to store all the points where the player's finger moves through during that circle gesture and attempt to discern if an enemy is within that space and then act accordingly.
--- probably other ways, too. But these jump to mind.

Interact with complex figure in iOS

I need to be able to interact with a representation of a cilinder that has many different parts in it. When the users taps over on of the small rectangles, I need to display a popover related to the specific piece (form).
The next image demonstrates a realistic 3d approach. But, I repeat, I need to solve the problem, the 3d is NOT required (would be really cool though). A representation that complies the functional needs will suffice.
The info about the parts to make the drawing comes from an API (size, position, etc)
I dont need it to be realistic really. The simplest aproximation would be to show a cilinder in a 2d representation, like a rectangle made out of interactable small rectangles.
So, as I mentioned, I think there are (as I see it) two opposite approaches: Realistic or Simplified
Is there a way to achieve a nice solution in the middle? What libraries, components, frameworks that I should look into?
My research has led me to SceneKit, but I still dont know if I will be able to interact with it. Interaction is a very important part as I need to display a popover when the user taps on any small rectangle over the cylinder.
Thanks
You don't need any special frameworks to achieve an interaction like this. This effect can be achieved with standard UIKit and UIView and a little trigonometry. You can actually draw exactly your example image using 2D math and drawing. My answer is not an exact formula but involves thinking about how the shapes are defined and break the problem down into manageable steps.
A cylinder can be defined by two offset circles representing the end pieces, connected at their radii. I will use an orthographic projection meaning the cylinder doesn't appear smaller as the depth extends into the background (but you could adapt to perspective if needed). You could draw this with CoreGraphics in a UIView drawRect.
A square slice represents an angle piece of the circle, offset by an amount smaller than the length of the cylinder, but in the same direction, as in the following diagram (sorry for imprecise drawing).
This square slice you are interested in is the area outlined in solid red, outside the radius of the first circle, and inside the radius of the imaginary second circle (which is just offset from the first circle by whatever length you want the slice).
To draw this area you simply need to draw a path of the outline of each arc and connect the endpoints.
To check if a touch is inside one of these square slices:
Check if the touch point is between angle a from the origin at a.
Check if the touch point is outside the radius of the inside circle.
Check if the touch point is inside the radius of the outside circle. (Note what this means if the circles are more than a radius apart.)
To find a point to display the popover you could average the end points on the slice or find the middle angle between the two edges and offset by half the distance.
Theoretically, doing this in Scene Kit with either SpriteKit or UIKit Popovers is ideal.
However Scene Kit (and Sprite Kit) seem to be in a state of flux wherein nobody from Apple is communicating with users about the raft of issues folks are currently having with both. From relatively stable and performant Sprite Kit in iOS 8.4 to a lot of lost performance in iOS 9 seems common. Scene Kit simply doesn't seem finished, and the documentation and community are both nearly non-existent as a result.
That being said... the theory is this:
Material IDs are what's used in traditional 3D apps to define areas of an object that have different materials. Somehow these Material IDs are called "elements" in SceneKit. I haven't been able to find much more about this.
It should be possible to detect the "element" that's underneath a touch on an object, and respond accordingly. You should even be able to change the state/nature of the material on that element to indicate it's the currently selected.
When wanting a smooth, well rounded cylinder as per your example, start with a cylinder that's made of only enough segments to describe/define the material IDs you need for your "rectangular" sections to be touched.
Later you can add a smoothing operation to the cylinder to make it round, and all the extra smoothing geometry in each quadrant of unique material ID should be responsive, regardless of how you add this extra detail to smooth the presentation of the cylinder.
Idea for the "Simplified" version:
if this representation is okey, you can use a UICollectionView.
Each cell can have a defined size thanks to
collectionView:layout:sizeForItemAtIndexPath:
Then each cell of the collection could be a small rectangle representing a
touchable part of the cylinder.
and using
collectionView:(UICollectionView *)collectionView
didSelectItemAtIndexPath:(NSIndexPath *)indexPath
To get the touch.
This will help you to display the popover at the right place:
CGRect rect = [collectionView layoutAttributesForItemAtIndexPath:indexPath].frame;
Finally, you can choose the appropriate popover (if the app has to work on iPhone) here:
https://www.cocoacontrols.com/search?q=popover
Not perfect, but i think this is efficient!
Yes, SceneKit.
When user perform a touch event, that mean you knew the 2D coordinate on screen, so your only decision is to popover a view or not, even a 3D model is not exist.
First, we can logically split the requirement into two pieces, determine the touching segment, showing right "color" in each segment.
I think the use of 3D model is to determine which piece of data to show in your case if I don't get you wrong. In that case, the SCNView's hit test method will do most of work for you. What you should do is to perform a hit test, take out the hit node and the hit's local 3D coordinate of this node, you can then calculate which segment is hit by this touch and do the decision.
Now how to draw the surface of the cylinder would be the only left question, right? There are various ways to do, for example simply paint each image you need and programmatically and attach it to the cylinder's material or have your image files on disk and use as material for the cylinder ...
I think the problem would be basically solved.

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.

Growing a visual tree with rectangles?

Given rectangle-shaped bars (say, of size 50x10), how would I grow-draw them to something that looks like a tree? A starting point is given where a semi-randomly bar is added, and then a new bar or two are added to every end of the old rotation, rotated by themselves, and with new bars added at their end, and so on to some point. I suppose it's a geometry question -- how do I find the correct bar ends to stick the new rotated bar too?
I'm using Lua, but any pseudocode would help, thanks!
Have a look at L-systems. They can be used to create plant-like structures. The Wikipedia article has many references to sites where you can toy with these.
Let's see if I understand well the core of your problem: you have a segment (bar) which you rotate around one of its sides by some angle and you want to know the position of the other end of the bar after that.
Isn't what you're looking for just the geometric definition of sine and cosine?
See below, sorry for my awful drawing skills :)
To make it "stick" just rotate around the right corner of the rectangle depending on the angle, like so:

Resources