Centering buttons programmatically in gamescene - ios

I created a simple game in Sprite Kit with Swift and in the beginning of the game I created a UIButton that says "start" and after pressing it, will start the game. But the problem is that the button that I created is centered in the middle only for iPhone 6. When I run it on iPads or iPhone 6+, the start button changes place.
Is there a way to center it for all devices? I am able to do this for UILabels by just doing labelname.position.x = view!.center.x. But for UIButtons, this does not work.

Try
buttonName.center = self.view!.center
You may not need autolayout, but if you have to, try
this video

Related

iOS Cloudy UIViewController Background

I am trying to create my first iOS app using Swift and Xcode 7.2. I am using SpriteKit to make Tetris. After the user loses, the view switches from a UIViewController with a SKScene inside it, in which the game runs, to a UIViewController that is a death screen saying the user's score and their high score. I was wondering if there is a way to have a background on the death screen have a translucent background so that the user sees the game they just played in the background. Any help would be great. Thanks:)
In the UIViewController of your game, you can add a SubView with a blur effect: http://www.ioscreator.com/tutorials/add-blur-effect-ios8-swift
Your view need to have a smaller zPosition than your "game over button" for exemple. So when the game is over, you add the "blurred view" and on it you add your other things like the score label. When the user restart the game you just need to remove the view and restart your game.

How can I detect if the Launch Storyboard happened?

does anyone know if there is a way to tell if the launch storyboard executed? Or is there a way to detect if the launch image was displayed?
Basically my app consists of just one view controller with some views (all created programmatically), plus the launch storyboard which I added to the project recently which seems to be working OK.
The reason why it would be useful for me to know if the launch storyboard happened is that my app is a game which basically consists of a big 2D scene that you can zoom into and pan around using the usual touch gestures. When the game starts for the first time it starts fully zoomed-out and centered on the scene: so that is what the launch image matches. But the player pans around and zooms-in on various things, so when they press the home button they could be zoomed into any part of the picture. So when they touch the app's icon to relaunch, if the launch storyboard happens it needs to put their pan/zoom position back to the initial centered zoomed-out position (otherwise as soon as the app gets going it would appear to the user to suddenly snap from the initial position represented in the launch image to where they were, not giving a smooth user experience).
What I do at the moment is -- if applicationDidEnterBackground: method gets called I assume that when the user relaunches the app, by touching the icon, that the launch storyboard will be executed. But the launch storyboard doesn't always happen after it hibernated via applicationDidEnterBackground:, especially if it is only a few minutes since the user pressed the home button.... and those times when the launch storyboard does not happen I need not inconvenience the player and put them back to the initial zoomed-out centered position, I could just let them carry on at the position they were.
I've not used storyboards before, but as I understand it launch storyboard are a special case where you can't make any connections to code because your app's not actually running yet, so I can't think of a way to set a variable, for example, to show the story board happened.
Anyone got any ideas?
Cheers,
Jon
Just use the viewDidLoad method provided by the UIViewController.
Just override the method in your ViewController and then you can perform the task you want when your View(Storyboard) is loaded.
Example:
#implementation MyViewController:UIViewController
-(void)viewDidLoad{
//Insert your code here
}
#end

Swift SpriteKit: Recognize multiple taps

I have a game and at the moment there is an AI player and human but I want to make it multiplayer. The game is designed where when you press the top left/right the sprite on top would move left/right and if you press the lower left/right the lower sprite would move towards the left/right. Imagine the iPhone to always be in portrait mode.
The issue is that I am using touchesBegan and I can't figure out how to make that work with possible multiple taps coming in at the same time

Animation in Launch Screen in xcode 6

I want to animate a set of images in my Launch Screen, but I do not know how. I have seen some tutorials telling me to put code in the App Delegate (DidFinishLaunchingWithOptions) and nothing has worked.
Could someone help me animate my Launch Screen?
I am supposing that you do quite a bit of work on launch, and you do not want your user to stare at a static image while this work is going on. What you need to do is do the work in the background (using gcd). This way, the launch screen will be gone quickly. However, you are not ready of course: hence your need for animations. So what I do is add my own equivalent of the start screen on top of my first visible UIView, do my animations and then tear down my start up screen. If you want to see what I do in action, try it out with my App (The Opera Player)

SpriteKit Game Centre Force

I'm creating an app and for some reason when I'm running the app on the device and the Welcome to Game Centre drop down appears, the force applied to my SKSpriteNode seems to be greater than normal, making my sprite fly off the screen.
So I add my sprite in the scene in the initWithSize method but then once you click on the screen, the touchesBegan fires which applies a force to the sprite, and if the Game Centre drop down doesn't appear (when you first start up the app) then it will work as per normal. Problem only seems to occur when Game Centre drop down appears.
Any ideas on a solution?

Resources