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.
Related
I am implementing a horizontal carousel-style character selection screen for a game (as per image below).
Image of carousel effect
The app is structured as one main GameViewController presenting different scenes; the CharacterSelectionScene being one of them.
From my research it seems that, although not always advisable to mix UIKit and SpriteKit elements, the best way to achieve the effect is the use a UIColectionView and add it as a subview to the scene. Because it takes care of the some of the animation and bounce effects.
Horizontal scrolling in SpriteKit (vs. a viewcontroller)
However, it's giving me a real headache! Using the post above as an example, I subclassed UICollectionView but I am unable to use the CharacterSelectionScene as the datasource and delegate! This would be ideal as the scene is where the data is loaded in from a plist.
I am currently using my CharacterCollectionView as the datasource and delegate by passing data from the scene via the collection view's init() a la:
collectionView = CharacterCollectionView(frame: customFrame, collectionViewLayout: layout, characterData: characterData)
This works but feels like a bad idea, it feels like a bit of a bodge. Maybe I'm wrong but as a fairly new programmer I'd just like to do this the right way!
Can anyone point me in the right direction? Am I going down completely the wrong path here or is this a perfectly good way to move forward. All advise/pointers appreciated!
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.
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.
I'm stuck on something, maybe someone can help me.
I'm working on a iOS swift game (I'm a beginner iOS developer).
In the StoryBoard I've added some buttons, some views, etc.
I've added a reference (of a rectangle) in my controller like (using ctrl+drag):
#IBOutlet weak var mainBoardGame: UIView!
In my GameScene I'm creating some SKSpriteNodes like:
playerSprite = SKSpriteNode(imageNamed: "playerImg")
playerSprite.position = ....
playerSprite.size = CGSize(width:...,height: ...)
self.addChild(playerSprite)
My problem is that this SKSpriteNodes are displayed behind the rectangle (mainBoardGame) created in my storyboard.
I've tried to add something like
playerSprite.zPosition = 100
but still the same.
I'm thinking that it would be better to add my playerSprite directly to my mainBoardGame (because it will be displayed inside of it) but I don't know how to handle a UIView and a SKSpriteNodes.
How can we add a SKSpriteNodes to a UIView ?
How to handle the z order between them ?
The main question is how to handle a UIView and a SKSpriteNode ?
Thanks.
The reason why I've build it in the storyboard is because I put some contraints in order to have a well displayed elements on each of the iPhone screen size.
Is there a way to do that in SpriteKit ?
C.C.
SpriteKit does not play nicely with subviews. SKScene wants to occupy a view entirely, so the high-performance 2D game engine can work its magic.
Why not just create your game board within your scene, and have the enclosing view occupy constraints? It's harder to provide a more specific answer without more detailed code examples.
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.