I need to have a game scene, and on the bottom a permanent game menu for things like inventory, etc. I thought it would be great to have two scenes: one for the actual game and another for the game menu. How can I do this in SpriteKit? Having two scenes at the same time (and each one having its own nodes and such)
Also, if this is not the best way to implement this, please tell me.
No don't do that. Even if possible it is meaningless.
In a such case I use storyboard. Created menu at top of the screen and give the rest of the screen to SKView. By this way you can control your SKScene easily also you can use UIKit for you menu which is more advanced than SpriteKit ui elements.
Also you can use one scene and create menu nodes with SpriteKit utilities.
Related
I am contemplating a simple app that has four characters that you can drag around on the screen. While dragging they "wiggle" — that's the animation. And they snap to a position if they get close enough to it... like in a puzzle. Without the animation, this is all simple in UIKit.
My first thought is to render each character in its own SKView inside a plain old UIView. I could attach UIGestureRecognizers to each SKView to track tapping and dragging. But I think this implies individual GameScenes for each character/SKView. That seems go go against the grain of SpriteKit.
The alternative is a single GameScene with the four sprites. But I would still need to track & drag them and I don't see how to do that within an all-SpriteKit app.
Is either approach better practice than the other?
You should implement the one that has a single scene and separate sprites for each character. The sprites will be SKSpriteNode instances which are SKNode instances, which descend from UIResponder and can, therefore, respond to touch events.
Look at the documentation for SKNode. It is a wealth of information that applies to sprites as well as to any other kind of node. In particular it says:
All nodes are responder objects that can respond directly to user interaction with the node onscreen…
And then later has a section on "The Hit-Test Order is the Reverse of Drawing Order" etc.
I'm following this question's advice on how to create my game world for a scroller game with camera centered on the player. However, the advice says to use an SKShapeNode; I don't know how I feel about that.
Are there any advantages/disadvantages to using either a shape node or an skscene (or another type of object/node)? Is there a node that is considered best practice to use as a world?
Also, is it possible to create an skscene inside an skscene, or is that bad practice/discouraged?
Thank you!
You can't put a scene inside a scene per-say but you could stagger view controllers and place a view controller on top of another and then put the scene on top of that inset view controller.
The way I implement my scroller games is to put the player in the center and then move the background around. (Checking for bounds of course.)
As far as your advantages/disadvantages I'm not sure what you mean by the SKNodes; that's how you should do it if you're working just in SpriteKit. But don't add another SKScene unless you have something that you can't implement in just one SKScene.
Just wanted your opinions on this. I am leaning towards UIView to hold my main menu and such, and just displaying it over the SKView when appropriate. Or I can have an offscreen node with the menu, or I can make a whole new SKScene to transition to.
Do you have any other alternatives or advice on the topic?
If we want to be specific about the scope of the game. It will be something along the lines of an infinite runner. So the menu would be pretty simple (Start, leaderboard... etc)
I'm also developing a SpriteKit game and also needed to display a menu with options and a settings menu, in my case, I found it better to use UiView to present most of the settings of the game as well as a tutorial view because it is a UipageViewController (to present images for how the game works) but here is the downside of either option:
If you choose to use views for menus and pause the game then the rootController must present it and any buttons, labels, images, etc must be presented and then removed, otherwise they will still sit on top of content. This works but animating stuff is difficult, unlike with another Skcene where elements like buttons can bounce, move, etc
The downside of using Skscene is that simple Ui-elements, like those I mentioned before, are now difficult to work with. For example instead of having a button you now have a node and you must therefore work with the touches methods: began, moving, and ending to make the node behave as a touch-up-inside button. Same with labels, and everything will have to be done programmatically whereas if you want to use views, you could make them in he storyboard and instantiate them as needed.
Conclusion: In my game I only chose to use Skscene for the game itself, (i.e playing) and used the views for pause, settings, about, tutorial. Hope this gives you some idea!
I initially started out with all these non-gameplay scenes as UIViews/UIViewControllers, but later on switched to having everything as an SKScene except for the welcome scene viewcontroller.
It doesn't seem very difficult having the options/settings/high scores type of screens under the SKScene option. You really only need to use one method to detect the UITouch:
touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
This works great with sklabels. You could easily load a spritekitnode behind the sklabel and get the same full effects of the UIButton with this combination. You can of course all all touch methods, but touchesBegan almost mimics the expected behavior.
With these views under an SKScene, you also get access to the update: method where you can get more creative in how you display animations and events.
I'm trying to build a scrolling table of game center scores in an SKScene. Is there a way to use sprite kit and storyboards/xibs? [self addChild:customTable] on an SKScene doesn't seem to work.
UIKit elements like UITableView, UIView, etc cannot be used as children of SpriteKit nodes. You can place a UITableView on top of a SKView/UIView but that comes out as crude. I would suggest you use a normal UIViewController to display your Game Center scores.
However, if you still need to display the scores using SpriteKit, there is a component called ScrollNode which might do the trick. You can find it here.
I'm building a tower defence game using SpriteKit and I'm relatively new to this.
My map basically consists of tile Nodes that are touchable. Once a user touches the node, I can place a tower on that node (I have this part working so far). What I want to do moving forward, is instead of directly placing a tower, I'd like a circular menu to pop up around the tile Node to let the user pick the tower that they wish to place in this tile node.If the user clicks anywhere other than the circular menu, the menu should disappear.
So something like this:
http://imgur.com/QvCsM8Q
I'm wondering what the best way to do this is. I have two possible solutions but they seem hacky:
1) Creating a custom UIView consisting of the menu and 4 buttons and then adding it to my scene (but then how do I detect button presses in this menu from the scence?)
2) Extending a SKShapeNode to create a circle and adding in 4 SpriteNodes around the circle, then verifying if a touch location corresponds to one of the 4 SpriteNode locations.
Any suggestions/code examples of how best to approach this?
I would suggest you create a separate class for your tile nodes (which inherit SKSpriteNode) and add the functionality within that.
For the approach for the menu, I think something along the lines of point (2) would be better. By subclassing the tile node, you can make the tile detect the selection by itself.
Expand the tile using SKShapeNode or a SKSpriteNode with a circular image using animation.
Place the four buttons on the expanded part.
Implement the touch for the selection within the tile node class.
For closing the menu, a tap on the scene can trigger a NSNotification for which the tileNode could become a listener on expansion.