Annoying black screen/ pause when loading game

Monkey Targets Forums/iOS/Annoying black screen/ pause when loading game

hobo(Posted 2012) [#1]
Ok - I have had this problem with my game for ages and now it's nearing completion I can no longer sweep it under the carpet.

I hope someone can help.

Basically all iOS apps including Monkey games (NSS etc) as soon as you press the icon button to load the game a 'loading' or 'please wait' graphic pops up immediately without hesitation.

The game then loads in the background and once loading is complete the title screen appears.

I cant re-create this. I don't know if its my xcode setup or something in my code or something really simple but the best I have achieved is a black screen and pause of about two seconds before my loading image pops up and that's just a test harness.

If I include the loading of all my assets its about 6 seconds of black screen/pause before the loading image pops up. Now it has a lot of assets so I don't mind the loading time, just need to get an image up on screen first before the loading takes place.

On HTML5 target this isn't an issue.

Here is my code:




Class MyGame Extends DiddyApp
	
	Field fGfxLoadingScreen:GameImage

	Method OnCreate:Int()
	
		Super.OnCreate()
		SetScreenSize(2048, 1536)
		SetUpdateRate UPDATE_RATE
		
		' Load the loading screen image 
		images.Load("loadingscreen.png", "", True)
		
		' Create the screen
		loadingScreen = New LoadingScreen()
		
		' Jump to loading screen
		game.Start(loadingScreen)
		
		Return 0
				
	End

	
End
	


'************************************************
'* Loading Screen
'************************************************



Class LoadingScreen Extends Screen
	
	Field fGfxLoadingScreen:GameImage
	Field LoadingScreentimer:Int
	Field LoadingScreenfade:Int

	Method New()
		name = "Loading"
	End

	Method Start:Void()
	   
                ' Set loading screen

		fGfxLoadingScreen = game.images.Find("loadingscreen")
		LoadingScreentimer = Millisecs()
		LoadingScreenfade = 0
		
		' Load all other assets here
		
		LoadSounds()
		LoadImages()
		
		smallBlackFont = New BitmapFont("fonts/segoe55black.txt", False)
		smallWhiteFont = New BitmapFont("fonts/segoe55white.txt", False)
		largeWhiteFont = New BitmapFont("fonts/segoe128white.txt", False)
		largeBlackFont = New BitmapFont("fonts/segoe128black.txt", False)
		
		titleScreen = New TitleScreen()
		gameScreen = New GameScreen()

	End
	
    	
	Method OnLoading:Int()
		Return 0
	End

	'***********************
	'* Load Sounds
	'***********************
			
	Method LoadSounds:Void()
		
		game.sounds.Load("1")
		game.sounds.Load("2")
		game.sounds.Load("3")
		game.sounds.Load("4")
		game.sounds.Load("5")
                 
                ' edited here but about 15 sounds to load in total
	End
	
	'***********************
	'* Load Images
	'***********************
	
	Method LoadImages:Void()
		
		' create tmpImage for animations
		
		Local tmpImage:Image
		
		game.images.LoadAnim("bank.png", 650, 224, 2, tmpImage)
		game.images.LoadAnim("combo.png", 650, 248, 2, tmpImage)
		game.images.LoadAnim("comboactive.png", 393, 204, 2, tmpImage)
		game.images.LoadAnim("gameover_arrow.png", 169, 161, 2, tmpImage)
		game.images.LoadAnim("titlesalaryman.png", 742, 970, 1, tmpImage)
		game.images.LoadAnim("tick.png", 193, 152, 2, tmpImage)
		game.images.LoadAnim("tutorial_mouth.png", 50, 38, 2, tmpImage)
		game.images.LoadAnim("card_highlight.png", 146, 323, 2, tmpImage, True)

                ' edited here but about 40 images to load in total
		
	End
	
	Method Render:Void()
		
		Cls
		
		If Millisecs() <= LoadingScreentimer + 5000
			fGfxLoadingScreen.Draw(SCREEN_WIDTH2, SCREEN_HEIGHT2)
		Else
			fGfxLoadingScreen.Draw(SCREEN_WIDTH2, SCREEN_HEIGHT2)
			LoadingScreenfade = 1
		Endif
		
	End
	
	Method Update:Void()
	
		If (LoadingScreenfade = 1)
			game.screenFade.Start(500, True)
            		game.nextScreen = titleScreen
		Endif
	End
	

End



Any help with this or suggestions to get an image to immediately appear pre-loading is really appreciated.

Thanks.


smilertoo(Posted 2012) [#2]
i'd try some sort of gamestate switch, only load the loading image then switch gamestate to assetLoader or something so the app begins rendering something.


benmc(Posted 2012) [#3]
Are you opening the project in XCode to build to your device? As far as I can tell, there's no way to set "Launch Images" or your icon directly from Monkey.

In XCode, go to the app's summary page (under TARGETS), and you will see where you have to actually drag and drop in 3 different images for that initial "loading" screen before any of your game assets load.

They are called "Launch Images" and you'll need one of size 320x480, 640x960, and 640x1136.

Then, when you tap your game icon, this shows first, and once it's ready, it will show your first "loading screen" image in your app. Otherwise, you'll get that black screen for a few seconds.


benmc(Posted 2012) [#4]
Also, in your code, it looks like it's calling "LoadImages" before a render even takes place. Could you set a flag to do an initial render first, then in OnRender set that flag to load the rest of the assets?


hobo(Posted 2012) [#5]
Thanks benmc was a combination of both those things.

Totally sorted me out. Cheers!