I have a simple scenario (default SpriteKit template): one ViewController and a MyScene SpriteKit scene.
In my ViewController I managed in viewDidLoad the gamecenter initialization but my scene after start immediatelly starts a rather quick sprite movement infinitely (a background parallax scrolling).
Everything works correctly but until GameCenter goes through the authentication procedure my sprite movement lags, breaks, not running fluently.
What practice can I have to minimize this (with keeping the parallax sprite movement running)?
I'm testing this on iPhone4 device (IOS7.03)
GameCenter authentication is actually something that has been causing lag in games for awhile. There are a couple ways people try to get around it, and it's really depends on the app and programmers taste.
Pause the game during GameCenter authentication
This is the easiest way typically, and pretty straightforward.
Put the authentication on another thread
If you desire a fluid option from menu to gameplay, this would be the route to go.
Just use GCD to start a new thread and run the GameCenter authentication in it.
Hope this helps. There might be a couple of other ways, but these are the two I've seen the most. I typically just use the first method.
Related
I am building a simple ios gaming app where I have to move a few objects on screen, and these moving objects react to swipe gestures and change their direction based on that. I am not using spritekit or any other gaming framework for this, and the way I am moving the objects is by triggering an NSTimer that fires 60 times a second. I am not using any threads explicitly so I guess the timer is executed by the main thread ? The code block that the timer triggers updates the location of objects based on their speed (defined as pixels per time unit in x/y direction). It is working fine and I am almost at the end of my project, but while testing the app I've realized that although the movement of objects seem pretty good most of the times, however sometimes the movement is a little rough/patchy.
My question is that is it the right way to do something like this, how can I improve the performance ? will using something like GCD can help with the issue of jittery movement ? (I haven't looked into GCD in detail but I am willing to spend time on it if I know that will help)
Thanks for any help !
and the way I am moving the objects is by triggering an NSTimer that fires 60 times a second
I would recommend not doing that. Various forms of animation are built in (View animation, Layer animation, CADisplayLink, UIKit Dynamics), and of course there's always Sprite Kit. Use the tools you are given for this purpose. Don't reinvent the unicycle when you already have a Ducati at your disposal.
I'm working on a SceneKit game using Swift, and I'm thinking about the best way to organize the various screens/ states surrounding the actual main game scene. I have a simple prototype which consists of three states:
Splash Screen (choose game type) ->
Game ->
Game over screen (choose to play again or return to splash)
In the prototype I opted to go for UIKit to do the UI elements, rather than a SpriteKit overlay. Although it's just buttons at the moment, which would be easy enough to do in SpriteKit, I might in future want to add sliders (eg an options screen to set control sensitivity etc), text entry etc, and then you end up recreating great chunks of uikit.
So at present, each of the 3 scenes described above has its own UIViewController. The Splash and Game ViewControllers have their own SCNViews and SCNScenes, and the GameOver is a modal that displays over the main Game scene.
This structure isn't really ideal, as it means that the main game SCNScene gets reloaded whenever the viewDidLoad of the GameViewController fires. The main SCNScene is quite detailed so takes a few seconds to load, and with repeated cycles this seems to create memory issues. After 2 cycles of Splash -> Game -> GameOver I get a memory warning, and after the third cycle Xcode loses the connection to the iPhone (which seems, in my experience, to be caused by memory issues).
I would like to have a main GameViewController that loads the most frequently reused assets once, but still be able to segue between the various menu screens.
So what are the options here?
I thought perhaps I could have a main GameViewController which controls the loading and unloading of SceneKit assets and has the sole SCNView. Its viewDidLoad method would only be fired once, when the app first starts. Then, each of the other views would have a very minimal UIViewController, which would be presented as modals over the main GameViewController, with "OverCurrentContext" selected.
I wanted to ask whether this pattern sounds feasible, and how others organise their SceneKit games. I'm still quite new to native iOS development, so it could be that I'm missing some basic game design pattern.
My Experience with the use of only one GameViewController (my current work for MAC OS X: i started a a 'small' 3D game with a MainMenu/start screen, a Hud and 2 or 3 complete different 3D Scenes - this shall be ported then to IOS, too):
In the last week i tried what you asked for, to use only one GameViewController for "all" that stuff - for me it seemed to be the easy and "good" way to do it - but even after lot of hours with all my tricks I've learned the last years i was not able to reload load another (or change) 3D scene (or even not another sprite kit scene hud) after a scenekit scene is loaded in a single ViewController.
Maybe there is difference between MAC OS X and IOS but i even tried this in an iOS version and it has the same behavior.
What i was able to do: You can modify a loaded 3D scene or change data in the sprite kit hud etc., so you are able to use one 3d scene to add or show the things up when they are needed but as far as my tests here showed, you will need one ViewController to show up a complete new different 3d scene or 2d/3d Menus etc. I will post my further experiences as soon as I'm a step further. i hope this helps a little.
How do you know when to use a loading screen before the game starts? I'm not talking about the splash screen that shows up when you open the app. I'm talking about an actual loading screen (usually with like a loading bar) before the game starts or before the menu options show up? (Examples: Angry birds, Ultimate Briefcase, Clash of Clans) How do you know when you reach the threshold of the number of assets, audio files, etc that need a loading screen? Do you put it in the scene file? or somewhere else?
(This is in context of Xcode / Spritekit)
Sorry for all the questions. Just trying to understand and make my game better. Thanks for the help!
Answer: You shouldn't use a loading screen unless you absolutely have to. Don't use one just for the sake of using one. Use a loading screen if there is a genuine perceivable lag. To determine whether your game lags, benchmark and test your code through the worst scenarios (maximum number of sprites etc.) even if they are unlikely to occur. To understand what constitutes as a lag, the following question will be of great help:
What is the shortest perceivable application response delay?
Where and how you should load your assets is entirely up to you. You should decide that based on many factors, but generally it depends on what happens in your game and how do you handle your resources internally (when do you need resources, when do you release them from memory etc).
I remember that in Apple's Adventure example game (not available for download anymore) all of the shared resources was preloaded at the beginning of the game. Still, you don't have to do that. You can preload your resources when it is appropriate for your app, or maybe you want to release the resources while you are in the menu (or in some other scene than a gameplay scene).
There is nothing written (like in the docs or somewhere else) about when you should show loading screen, or even a rule that you must have a loading screen. The point of a loading screen is better user experience.
Personally, if you have to make a user to wait like 10 seconds before the game starts (which is rare actually), I would do two things there:
1) Show loading image (or something animated, like spinning animation)
2) Show hints or interesting facts about the game, like every 3 seconds (or whatever is an acceptable delay in this situation). This way, you introduce a player with the game while he waits, which is better than let them just wait and look at spinning animation.
I am new to the iOS platform and have written an app using Sprite Kit and Xamarin. To transition between scenes I am using NavigationController.PushViewController with a "Back" button on the new scene to return. This works fine.
My problem occurs when I go back and forth between the original scene and next scene about 3 times. The frame rate (and overall application) slows to a crawl, and depending on which scenes, will hard crash. This happens only on device and not in the simulator. My gut instinct says I'm leaking memory somewhere / not cleaning up properly, so I have just started getting up-to-speed with Instruments. Note that each scene has about 5-8 images on it.
Questions:
What is the proper way to clean-up after transitioning out of a scene back to the previous one? I am explicitly calling RemoveAllActions() and RemoveAllChildren() to ensure clean-up.
What is my best strategy when using Instruments? I've only just begun to experiment with an Allocations trace, but there are a lot of allocations and knowing what to look for is challenging.
Any help is appreciated. I am considering dumping Sprite Kit altogether since my app doesn't really need it (I wanted to experiment) and because it has been a challenge building the app with all kinds of deep crashes (e.g. SKShapeNode, which is very problematic).
Thanks.
How can I implement a starting/launching animation of a app in the best way possible? of course mainly in terms of performance?
Starting with sprite kit I occured the problem of deciding the best way to implement a starting/launching animation (like in skype or twitter or other apps that have a animation before the app becomes active) for my game.
I tried to make the animation using a node, but somehow it doesn't feel right. The animation is not yet part of the game.
SKSpriteNode* startScreen;
[startScreen runAction:[SKAction animateWithTextures:startImages timePerFrame:kDigitTimePerStartAnimation] completion:^{
[self animationStopped];
}];
Doing it in the first game controller as a UIImageView with some images to be played also seems not right because Sprite Kit is the one optimised for working with graphics.
[imageView startAnimating];
(I know it's not a big deal for the iOS to run some images in sequence, but I'm a little bit idealistic).
Waiting for proposals.