Why is Unity Ads 'Advertisement.Initialize()' making my game lag? - unity3d

When my game starts the welcome screen has quite a few animations that play out. It was working fine until I implemented Unity Ads into my game. Now there is a noticeable lag when this bit of code executes:
Advertisement.Initialize ();.
It only lasts for a second but it is quite nasty. I tried putting the code in a co-routine and calling after the bulk of the heavy animations are completed but it still causes a considerable disruption to the remaining simple animations that are looping.
I'm thinking about putting it inside of my "Earn Button" onClick event but then the user will have to wait for the ads to load up which can take up to 5 seconds in my experience.
Is there a way I can call this code while the splash screen is loading?
I am testing on a Samsung S5 if that helps.

I think it takes long because it will download video Ads and try to cache them into the device. It will take even longer for devices with slow internet.
I assume you tried to use AsyncTask Here , if not, give it a go and Initialize UnityAds on a separate thread and see if it helps.
Another way is to call Initialize() and then check if the Video Ad is ready and put a loading screen while its downloading all the video Ads.
something like
While(! Advertisement.isready())
{
// loading..
}
I am not sure if it downloads videos every time you open the app or once every sometime, you need to ask UnityAds for that.
you get the idea.. hope this helps

Related

How to delay the start of a function

so i have built my first application in X Code using swift, and i have also taken the time to add the game centre functionality to it, however my question is, how would i delay the start of my game, in order for game centre to load, as of right now, the game starts, and then the game centre banner appears on top of my game before disappearing.
would it be sufficient to use something like, on the function containing my main game attributes:
NSTimer.scheduledTimerWithTimeInterval()
or
would i be better off adding a splash screen?
if anyone has any other suggestions, that would be helpful.
thanks in advance.
Better to subscribe under GameCenter, listen a complete event and then produce your next initialization. Avoid timers in similar situations, because time of processing depends from many factors, and rely to specific delay is not good idea.
If you are waiting for the game to load, then starting a timer is probably not the best solution, because you don't know how long the loading takes on different devices with different capabilities.
A better idea is to load your game and then have a completion method that is called to start the game when it is ready to be run.

Lag when authenticating local user on Game Center

For my cocos2d game, I authenticate the local user in the applicationDidFinishLaunching method of my AppDelegate. However, whenever the authentication is complete, it will cause a short lag in my game when the little "Welcome back, X" message slides down and back up. The problem is I have no control over when this authentication is complete – obviously the duration is highly dependent on the data connection of the device.
Sometimes the message (and the un-avoidable accompanying lag) appears as soon as when I am in the menu scene, which is somewhat acceptable, since my menu is more or less static. More often than not, it happens later, when the game has already started. Because my game is an endless scroller, the message always causes a lag in the movement of the player, even causing the player to die sometimes (half a second of lag is enough :-/).
How might I circumvent this? I used to have a loading scene right before my menu scene to load some of my assets, and because the loading takes a while, there was always a good chance that the authentication is completed at the loading scene, but of course I can't guarantee that it will be true!
Game Center can make the game freeze for a little as its starts if your connection isn't great. I doubt that loading GameCenter on a different thread would be a good idea (or even have an effect on that) but what you could do as a work around of the issue you are having is to give the game a 3-2-1 countdown before it starts scrolling/moving. would give a little more time for game center and time for the player to build his focus, starting serious in a game straight away might not be to the liking of some players.
I hope this helps.

Is it a good idea to use an video as splash screen in my iphone app?

I'm about to finish an app and now I wanted to add an animated splash screen with my company logo after the app finishes loading and launching. I can just use an animation with openGL for this, but I was wondering if it would be better to use a video..it's easier for me and the artist because he will only provide with an small video which i would reproduce after my app finish launching..less work.
I wonder if it's a good idea to do so...can I reproduce a small short video with the logo of my company or should i stick to making an animation ?
Also, reproducing video is memory intensive ?, because I'm loading some texture after my app finishes launching, and im wrried about that.
If i end up reproducing an small video, can i make it non interactive ? ( no pause, play stop, ect) so it looks like just as another animation to the eyes of the user ?
My other preocupation is quality...the quality of the video will look dramatically different to my animations in openGL ?
Thanks !
I can't tell you about the technical stuff, but what I can tell you is: don't use a splash screen. Directly from the Human Interface Guidelines:
Supply a launch image to improve user experience; avoid using it as an opportunity to provide:
• An “application entry experience,” such as a splash screen
...
Because users are likely to switch among applications frequently, you should make every effort to cut launch time to a minimum, and you should design a launch image that downplays the experience rather than drawing attention to it.
The HIG guidelines are intended (as far as I can tell) for Apps on the iPhone.
This is different from Games on the iPhone.
If your app provides some utility to the user, I agree completely with #Costique, #fabian789, and the HIG. The app should start instantly, with minimal loading and other distracting crap.
For a game, however, intros and the like are not only expected, but can also lead to a better user experience. My recommendation is to use a UIView Animation for only a small portion of the screen (the logo only). See Angry Birds as an example - their "animation" starts the same time the user's options do, so your animation (while quite pretty) doesn't block the user from using your app.
Disclaimer: the following is an entirely subjective humble user opinion. Please, don't take it to heart.
I hate video splash screens on my iPhone/iPad, however beautiful and stylish. What I like is apps which launch instantaneously. On iOS 4 chances are, I will see the startup animation once a month when the OS decides to terminate your app when the device is low on memory. So, now I tap the app icon and see the animation, now I tap it and don't (because it's already launched). It's inconsistent, out of your (and my) control, and ultimately makes little sense.
From both quality and aesthetics points of view, I think GL animation would better fit (hopefully) intense addictive action which follows. I'm not sure, however, that you will be able to load any resources in the background, while the animation plays, without making the animation stutter.

iPhone Opengl game with ads == fps problem?

I have a game that runs fine as is (around 30fps), but fps went down the drain when I tried to implement ads. I tried Greystripe and iAds but with same result (iAds were maybe bit worse). Average fps is almost same, but there are huge spikes all the times (1-2 spikes per second) and game is unplayable.
I guess it is because ad is in another view. I read somewhere that opengl apps on iphone don't like having another views with them, but there is plenty of games with ads on app store. How do they do it?
My implementation should be ok. I did everything as documentation and samples told me. I have my opengl view and ad view as subviews in app window, adview being in front of opengl view and thus covering part of it. Could this be the problem? Is it better to make opengl view smaller to left space for ad so they don't overlap? Do you have any other ideas what could be wrong?
Lope, I've created a gist at this link with a singleton "AdManager" class I wrote to handle iAds using cocos2d. Cocos2d sits on top of OpenGL, of course, and I've found that this code doesn't affect FPS even for relatively complicated games.
You'll have to modify this a bit to work with your application, changing out the cocos2d calls, etc, but this will give you asynchronous loading of iAds, which should help the FPS issue.
To use this class, include its header and call
[[AdManager sharedManager] attachAdToView:self.view];
wherever you need iAds. The ads will remain hidden until an ad loads, at which time they'll pop up at the top of screen. (The class works for iOS 4.0, 4.1 and 4.2).
Also, I should add that I have cocos2d running inside of an overall UIViewController that I call "Cocos2DController". When I attach the ads to a cocos2d view, I'm using
[[AdManager sharedManager] attachAdToView:[[CCDirector sharedDirector] openGLView]];
Best of luck!
We can hit and miss with apple's choices, but go for the sure thing and implement the ads in other parts to be appealing and not intrusive. It will be better for the framerate, and for you.
Try downloading the ads in a seperate, low priority, thread. You can, thus, nsure that the ads loading does not take too much CPU time. With a bit of CPU synchronisation you can make sure you don't try to display the new ad until it is completely ready to display. Sure it will suck some CPU time away from what you are trying to do but set your priorities right and it should only suck time when you are busy doing nothing.
Please excuse the thread necro'ing here, but I've used Stack Overflow a lot to help me through the problems I've had during coding, and thought my experience might be useful to someone in the future.
My simple cocos2d game ran with decent FPS (rarely changed the FPS display at all) until I implemented AdWhirl (integrating AdMob + iAd only). It would then run OK for the first few iterations, but upon upon the 9th or 10th scene refresh (single screen game, time in each scene < 5 seconds on average) the FPS would dive to ~20FPS, and drop again each time the scene refreshed.
Turns out, in my n00biness (this may be particular to me :) ), I was calling the scene from within itself. That is, once the actions had finished, the last action was to call the main scene again (a lazy way of rebuilding the scene for the user to have another go). This init'd the views and view controllers I had inserted to handle the AdWhirl ads all over again, and not only did I have a memory leak, I had 10+ view controllers all trying to request and service ads from AdWhirl. Once I got a clue and took that self-referring loop out, all was good.

iphone MultiTasking?

Hello I'm trying to get the multitasking work properly, but unfortunately I'm kinda lost. My problem is when I re-enter the game, it takes several seconds for the game to come back and show the pause screen. My question is; is there any way to put some sort of loading screen until the game comes back, so I can at least indicate that its not frozen? I've never used Xcode directly. I'm using Unity 3d to build my game. I made a little bit of research and if I'm not mistaken I'm supposed to use "applicationDidEnterBackground" app delegate method. My question is How can I put a custom loading screen using that method in Xcode?
Thanks
In -applicationDidEnterBackground:, you're given the opportunity to "clean up" the UI before the screenshot is taken. Apple says you should remove "sensitive data" (the screenshots might be persisted to "disk"?), but it also lets you do other things. In one app, we hide the label on a countdown timer so it doesn't appear to jump when you switch back to the app.
To change the "loading screen", simply display a full-screen view over the other views and remove it in -applicationWillEnterForeground:. Alternatively, pause the game in the first place!
(Really, you should be pausing the game in -applicationWillResignActive: which happens when the user double-taps home or the user receives a SMS/notification. I'm pretty sure it's called when the app is backgrounded, too.)