I am building a spritekit game with 2 screens. Inside the 1st screen the player should pick one Hangar out of 6-7, by horizontal scrolling. When one picked a new SKScene will appear with the actual game play. For scrolling - One Hangar should be centered, while two others are partly shown from the sides.
Can it be done with UIScrollView, on top of SKScene? Or better use sprite nodes for it?
I am just not sure about the best way to handle user interface with sprite kit.
I would implement this by putting the hangars as children of a SKNode. Swiping would move this this SKNode move around with all it's children.
If you wanted the positioning you described; when the swiping has stopped I would use an SKAction to center a the hangar closest to the middle of the screen.
I would do it like this because I think you should only mix in UIKit when necessary because :
It is easier to port to OSX
You don't have to convert between different types of coordinate systems
Related
In my ViewController, I have a background view and a bunch of collision views. I have added gravity behavior to those collision views, so that they will fall from their original positions. But I want to let these views stop falling when they reach the bottom of the screen. So I add collision behavior to each collision view. Meanwhile I don't want them to collide with each other. In another word, each collision view can overlap with other collision views. I have tried
[_collision setTranslatesReferenceBoundsIntoBoundaryWithInsets:NO]
But it does't work, and I guess I'm using the wrong method. So how can I achieve this?
I am new to sprite kit. Does anyone know how to divide the view controller into two parts. One is fixed and the second one is movable (I mean like two screens)?
You could create a UIView as a container for your whole screen and within that UIView add two SKViews which would be your "two screens" that you could do with as you needed.
You could give them the sizes you require by getting the first views height and width and set the SKViews proportionally based on that size. Such as an SKViews frame would be the parent UIViews height divided by two.
What are you trying to do? You may not need two controllers. You can use an SKNode as a "screen" in many circumstances. I believe it's also possible to put two SKScene into one view.
So, what does the motionless screen do, and what does the movable screen do?
If it's something like a minimap / menu (like Nintendo DS) then you can easily do that with an SKNode.
You don't need two screens to "ignore" the motionless part of the screen... you get the touch inputs every frame--it's up to you what to do with them. In other words, if the user touches the non-moving part of the screen, you can just ignore those inputs.
Im making a scene for my game. Right now i`m working on the view for IPhone 5-5c-5s the orientation is in landscape. But the view was not big enough for my scene, so i made the simulated size to freeform so i could choose the width for the scene. (Im using a normal Viewcontroller).
In the game you are supposed to move an image to another image without colliding with obstacles. The users playing the app are going to move an image from one side of the screen all the way over to the other side to the other image to win.
But when my image moves, the view doesnt follow with my image. How do you do that?
I would be so thankful for any answear! Thanks.
I am assuming you are using SpriteKit yeah? The UIView size is not related to the scene size. So changing those will not make your scene any different.
To do what you are describing, you need to read the Apple's Official Documentation on SpriteKit.
https://developer.apple.com/library/ios/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/Actions/Actions.html
Scroll down to Example: Centering the Scene on a Node
Basically Apple tells you to add a dummy SKNode to put all your world sprites into the scene, and then add another SKNode as "camera" into the dummy node so you can move it around.
If you are targetting only iOS9 and above, you can use SKCameraNode and set:
SKCameraNode *cameraNode = [SKCameraNode new];
cameraNode.name = #"camNode";
self.camera = cameraNode;
Then you add your "character" (that is to be moved together with the camera) into the cameraNode. Then any movement, you need to move the cameraNode instead of the "character".
I have an iOS SpriteKit SKScene that contains a UIKit UITableView as part of the scene via View.AddSubview. Generally this works fine. I then create an SKNode that temporarily sits on top of the scene (to zoom in on a particular image) and I want it to be at the top of the z-order, so I set ZPosition of the new node to 999 arbitrarily. When the node is added, it appears on top of all the other SpriteKit nodes, but the UITableView is still at the top of the z-order and still accepts input even though there is a sprite node on top of it (supposedly).
Is there a way to set the z-order of a UIKit view when it is hosted on a SpriteKit scene so I can push it backwards?
Thanks for any suggestions.
This is not possible. Any UIView added to the SKView sits on top of everything rendered by the SKView. Nodes rendered by SKView and the SKScene itself aren't views, they are elements inside the SKView much like table cells are part of UITableView, but you can only change the draw order of the UITableView and the SKView. You can't take individual elements (nodes or cells) and draw them outside their container views.
The same issue exists in other 2d renderers by the way, be it cocos2d or plain OpenGL.
I decided to jump into SpriteKit to start working on a game and I'm a little stuck on how I would create a scrolling menu (like Cut the Rope or Angry Birds for example) that would scroll through the various chapters in the game. I know that when I used Cocos2D there was a CCScrollLayer that would take the items (such as images or buttons) for each chapter and then create the scrolling layer but I can't seem to find something similar in SpriteKit. I was thinking that I could probably use a UIScrollView, but not sure if that is the best way to go or if anyone has found anything else that would work for this.
I have found that using a UIScrollView works well for me. From an SKScene you have access to the parent view; self.view. From the scene's didMoveToView: method you can add a UIScrollView and remove/hide it from the willMoveFromView: method.