ios launch animation with sprite kit - ios

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.

Related

using NSTimer to move objects on screen

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.

Should I use Core Animation or SpriteKit/Cocos2D for simple, blinking 2D animation?

I need guidance in how to animate small 2d things such as, for example, a character that simply remains blinking. Are SpriteKit and cocos2d "too much" to implement this sort of things? I'm not planning to make a game, I just want to mix standard iOS controls with artwork performing simple animations like the mentioned, but maybe I'll need to make more elaborate animations in a near future (a character running, for example). Should I use Core Animation framework for this? Or maybe another and better alternative?
I'll support iOS 7.0+
Thanks in advance
Core Animation is best here, since you're specifically wanting to cause a user interface element to blink (rather than building a game with a board and sprites). Use Core Animation to set up a repeating animation to change its alpha value.
Use of timings (like Ease-In-Ease-Out) can even add a "Mac sleep light" breathing effect. Using this versus iZabala's (admittedly functional) approach means you're letting the system decide if every single frame of this animation can be run in a given moment. If it's too busy to animate and keep the UI responsive, Core Animation will drop frames as needed.
You can also group animations (so if you have a "bank of buttons with blinking indicators", you can run them all in the same animation group with the same timing so they don't get out of sync with each other and look like a sparkly Christmas tree).
You can use the class NSTimer to call a function each X time. For example, if you want something to blink you can do something like this:
NSTimer* myTimer = [NSTimer scheduledTimerWithTimeInterval: 1.0 target: self
selector: #selector(blink) userInfo: nil repeats: YES];
-(void) blink { //supose that myObject is an UIView in this example
if(myObject.hidden){
myObject.hidden=NO;
}
else {
myObject.hidden=YES;
}
}
You can do the same using position to move, alpha or transparency to fade out, fade in... play with the properties the object has.

Gamecenter init/authentication makes SpriteKit's sprite movement lagging

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.

Showing a loading graphic in cocos2d which does not lag or stutter

In several cases, I want to show some sort of loading graphic/screen while my cocos2d iPhone game is getting ready. For example, it might be creating CCSprite objects in the init method of a new scene, caching textures via [[CCTextureCache sharedTextureCache] addImage:fnTexture];, etc.
Unfortunately, all these operations need to run on the cocos display thread. This means that any attempt I make to create some nice animations (e.g., a spinning graphic) essentially lock up while the thread is working, and my pretty animations freeze.
I can think of three possible solutions...
Insert artificial delays between the expensive operations, giving my animation time to update. Unfortunately this still leads to jittery animations, and definitely reeks of "code smell."
Somehow create a 2nd cocos2d rendering thread, short lived, for the animation...? I can't find any documentation on if this is possible.
Use a plain old UIView pasted overtop my OpenGL view, which is of course running on the main thread and thus not subject to these constraints... however, this would require figuring out how to code my pretty animations into UIKit
Is #2 possible? Or... is there a better way to go about this?
look MBProgressHUD on git. I did a quick test like so (took 3 minutes to put that in my game) :
MBProgressHUD *hud = [[[MBProgressHUD alloc] init] autorelease];
hud.xOffset = kScreenWidth / 2;
hud.yOffset = kScreenHeight / 2;
hud.progress = .5;
[hud show:YES];
[hud setTaskInProgress:YES];
hud.labelText = #"Loading";
[[CCDirector sharedDirector].view addSubview:hud];
giving me this :
it animates superbly through some pretty intense texture preloads and scene setup/computations. You can figure out the 'how to integrate' in your app ... API is nice (delegate, etc...)
Unfortunately, solution #3 did not work, because cocos2d on the iPhone actually uses the main thread for the cocos2d thread (however, this solution would work on OSX, because it uses a separate thread for cocos2d).
My eventual solution was based upon the reply from #LearnCocos2D (above).
First, using addImageAsync: eliminated most of the main-thread locking. The remaining lag had to do with creating CCNode objects (eg, CCSprites). I used a variation on solution #1 to create a cache of pre-built cocos objects in my loader class, which could then be reused later on (eg, while rendering layers) to prevent needing to allocate objects at runtime.

ipad sprite/atlas animation

I have an iPad app, where I need an animation full screen - running in a transparent UIView.
This animation is running every time the user is winning.
The question is, would you go for a sprite animation with a very large image as the source or would you go for a small video clip?
Remember that it has to be transparent - it is starts floating around.
Any input regarding directions is appreciated.
Thanks
I would use a sprite, loading a movie each time user wins is much more expensive than simply showing a sprite.
Besides, to show a video with transparent background you will have to iterato throught all player controller subviews and change backgroundColor like this

Resources