Okay i need the best possible way to achieve an ingame menu in my game . I'm using spritekit, i was thinking of making an uiview with its nib file and then add that to my scene but then it being an uiview and my area of implementation being a skscene i won't be able to relate them so what other ways can i implement it?
Is it possible to setup a new spritenode to act as the game menu and then add buttons and labels into it? and then add it to my scene whenever i need it?? Thanks in advance :)
Yes you can nest SKSPriteNodes just like views to create a menu layout. Here is an SKButton class you can use (SKButton) to create the buttons.
Related
I'm making an app where I have a tower in the background rendered with SpriteKit. The tower is made out of different blocks where I get the data from. I want to display this data in a UIView with different UILabels, etc...
Here's an image of the UIView and UILabels I try to link
https://imgur.com/vOw5QoW
The problem is that I can't figure out how to link my labels and view to my SKScene code (which is not possible I know). I'm struggling to find a way to link these UI objects to my SKScene code (Show and hide the view when a certain action happens etc...)
Is there a way to link these 2?
(I know the existence of creating UI elements with SK code, but that's not what i'm looking for.)
If you want to display both SKView and UIView on the same screen, you can use Container View Controllers.
You define "container views" in your storyboard and assign them to separate view controllers via "embedded" segue.
Here's a good article on doing it - https://useyourloaf.com/blog/container-view-controllers/
I am creating a game where I created a UI for my main menu screen and I want to apply the play button to show on the play button shown in the image below. I know how to do it via with main.storyboard but don't know how in spritekit. So, when they click on the play button it will go to a different scene which is the (GameScene)
here is the image.
You can approach that in two ways. Either you stick with SpriteKit and handle interaction yourself or you mix SpriteKit with UIKit. In the first case, you would subclass SKSpriteNode or create a SKNode subclass with a SKSpriteNode child
SKSpriteNode(imageNamed: "...")
and handle user interaction by overriding the touchesBegan or touchesEnded functions. Or you go with UIButton created with code.
UPDATE
Decided to make a quick generic implementation of a SpriteKit button. You can try it here, but keep in mind it was a quick first commit:)
I wouldn't have a single image for your scene that has the buttons included on it. There is no room for scalability like that. I would create those buttons as a subclass of SKSpriteNode and add them to the scene as objects. That way if you move around the button you don't have to redo your background image. #Konrad.bajtyngier Is on the right path with his implementation, and I use something very similar in all of my games (it becomes an indispensable object that gets copied from game to game). His implementation uses closures () -> () to carry out the actions, there is another option in you can use in your sub class as well.
in your subclass add a delegate
protocol ButtonDelegate: NSObjectProtocol {
func buttonWasPressed(sender: Key)
}
weak var buttonDelegate: ButtonDelegate!
and when you create your button just add they scene as the delegate of the button.
button.buttonDelegate = self
and then in the scene add the buttonWasPressed func. This way you'll will know what button was pressed and handle it accordingly and not have to worry about your objects getting retained by using closures.
I don't feel one method is better than the other, but you should strongly consider sub classing your button, and remove the button backgrounds from your background image.
please see my answer and code here for full details
Make touch-area for SKLabelNode bigger for small characters
Language: Swift, IDE: Xcode for iOS development, Single View Application > View Controller...
I have 2 UIImage Views with identical images that I'm scroll-animating from left to right across the view in order to create a 'slowly-moving background' of sorts. I'd like to place other UI elements (Labels, other images, etc.) in the foreground of this repeating background animation, but find when I run the simulator the foreground image isn't seen...
Question: Is it possible to force other UI elements to stay in front of a repeating animation programmatically?
I'm not at my Mac so I can't share my code at the moment, but if you know a straight answer to the question and/or which method could best achieve this, I'm all ears!!
Thanks in advance! :)
This depends on the z-ordering of the views. Assuming you are adding all of your views then starting the animation call bringSubViewToFront on the view you are animating right before you start animating it. If you are laying things out in interface builder the Z order is based on top = farthest and bottom = closest. If you are adding view programmatically the newest view is always added in front. You can change this with insertSubview:at: and the related methods. Take a look at the documentation for UIView.
If you want z-index use:
YourImageViewName.layer.zPosition = 1
Also you could play with bringToFront method on the parent view:
self.view.bringSubviewToFront(YourImageViewName)
Hope this fix your problem.
I've written a small multiplayer game for the iphone. Once one of the players win, I want to display him 'You Win' image and a button so that he can play again.
How can this be done? One option is to use a segue to a new view-controller, but I think this should be shown with the game in the background. What would you suggest, as I'm pretty sure this is a common scenario for an iphone game/app.
EDIT: I ended up using both Phillip Mills's answer and Selkie's answer. Here is on How to Use UIView transitionWithView?
You can create the custom view and keep it as a separate property within your main game view controller. When someone wins, add it as a subview to the view property of the controller. It can be full screen size with transparency so that it's effectively modal, yet shows the game as background.
You can make it as a view, then show it using UIView animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations
The animation block could be sliding up, fading or whatever you want.
The other way is to add it at the beginning, but set its hidden property as YES. Change it to NO when it's needed.
I am trying to make graphics move randomly in cameraview. Is there any way that I can get the balls moving in camera view? Or any tutorials that any one of you may refer me to?
To do so, you will need to implement your own camera view: make UIViewController class, set UIImagePicerControllerSelegate to it, implement all necessary methods to make imagePicker work, set useCustomInterface property to "NO" and then, add any sub views to your custom camera. You may also make them move as you like.
In 5 words, implement your own custom camera.
Here is poplar question about what you need: iPhone: Camera Preview Overlay