Cocos2d: Black Screen after loading scene - cocos2d-iphone

I am developing a game where I need to reload scenes many times.
What I decided to do is when I finish each level to clear my current scene, create another "buffer" scene and then reload the first one (after having cleared my memory).
The problem is that after I get from the buffer scene to the last one, a black screen appears. In the console I can see that the last scene was loaded and initiated correctly but still nothing appears..
Any ideas?
Thank you for your help!!!

Related

How to load the loading scene background in cocos2d without blanking out?

I have a cocos2d game that has a loading scene where we load a bunch of assets. The game starts with the splash screen, and then launches the loading scene. The loading scene starts by loading the background, so the user sees the loading scene background while the assets are being loaded.
I load the loading scene background by calling CCSprite::spriteWithFile: and passing the filepath: loadingbackground.pvr.ccz
It seems to work differently on different devices:
On iphone (3gs) simulator, I see the loading scene as expected.
On iphone retina simulator, I don't see the loading scene (there aren't many assets yet, so may be happening quickly) and it goes directly to the main menu scene.
On the ipad 3 device, the splash screen comes up, and then there is a half second of black screen, and then the main menu scene shows up.
I want to see what I can do to avoid that black screen showing up on iPad 3. I suspect this is because of the time taken to load the loading background.
I have tried the following optimizations (mostly based on #Steffen's blog post on memory optimization):
Moved the loading background (originally 2.3 MB RGB8 png file) into a pvr.ccz spritesheet by itself, which reduced its size to 1.8 MB.
Removed the image from the texture soon after use.
I still see a black screen on iPad 3. Any suggestions?
Update: Found the issue - I had some code where I was overriding OnEnter and calling [[CCDirector sharedDirector]replaceScene] in it, and also calling the same from the background thread. Removed the OnEnter overload and it worked without flicker.
Thanks
Ignore whatever happens in Simulator. That's not relevant, focus on the device.
When the loading scene initializes and you add the loading scene's background, make sure you schedule update and load your assets in the update method. Otherwise if you load the assets in init, the background won't be drawn because you're loading all the assets before cocos2d gets to redraw the screen.
If this still fails, simply send the visit message to the background sprite followed by [[CCDirector sharedDirector] drawScene]. This forces a redraw of the scene.
Is this cocos2d-iphone or cocos2d-x ? make sure the tags are correct :)
I think you're referring to the startup flicker, there are a few ways to avoid that.
first thing you need to make sure you're handling the rootViewController correctly for iOS 6 and iOS 5 and below, there are a little changes for each.
You can find a little reference here:
http://www.cocos2d-iphone.org/forum/topic/34471
Second thing you need to know that simulator's behaviour is not stable, you should always rely on real devices for testing, but it's very likely you'll still have the flicker issues.
Sorry I didn't provide example code, but you haven't supported enough information to know what's the real issue here.

OpenGL window draws fine, but all the windows on top of my OpenGL window go black

I have an app that mixes OpenGL with Motif. The big main window that has OpenGL in it redraws fine. But, the sub windows sitting on top of it all go black. Specifically, just the parts of those subwindows that are right on top of the main window. Those subwindows all have just Motif code in them (except for one).
The app doesn't freeze up or dump core. Data is still flowing, and as text fields, etcetera of various subwindows get updated, those parts redraw. Dragging windows across each other or minimizing/unminimizing also trigger redraws. The timing of the "blackout" is random. I run the same 1-hour dataset every time and sometimes the blackout happens 5 minutes into the run and sometimes 30 minutes in, etc.
I went through the process of turning off sections of code until the problem stopped. Narrowed it down more and more and found it had to do with the use of the depth buffer. In other words, when I comment out the glEnable(GL_ENABLE_DEPTH_TEST), the problem goes away. So the problem seems to have something do with the use of the depth buffer.
As far as I can tell, the depth buffer is being cleared before redrawing is done, as it should. There's if-statements wrapped around the glClear calls, so I put messages in there and confirmed that the glClear of the depth buffer is indeed happening even when the blackout happens. Also, glGetError didn't return anything.
UPDATE 6/30/2014
Looks like there's still at least one person looking at this (thanks, UltraJoe). If I remember correctly, it turned out that it was sometimes swapping buffers without first defining the back buffer and drawing anything to it. It wasn't obvious to me before because it's such a long routine. There were some other minor things I had to clean-up, but I think that was the main cause.
How did you create the OpenGL window/context. Did you just get the X11 Window handle of your Motif main window and created the OpenGL context on that one? Or did you create a own subwindow within that Motif window for OpenGL?
You should not use any window managed by a toolkit directly, unless this was some widget for exclusive OpenGL use. The reason is, that most toolkits don't create a own sub-window for each an every element and also reuse parts of their graphics resources.
Thus you should create a own sub-window for OpenGL, and maybe a further subwindow using glXCreateWindow as well.
This is an old question, I know, but the answer may help someone else.
This sounds like you're selecting a bad visual for your OpenGL window, or you're creating a new colormap that's overriding the default. If at all possible, choose a DirectColor 24-plane visual for everything in your application. DirectColor visuals use read-only color cells, but 24 planes will allow every supported color to be available to every window without having to overwrite color cells.

How to reset a scene in cocos2d?

I am using cocos2d to create a simple arrow shooting game.On reset button I am replacing the scene to The same play scene i.e i am loading the images again and again on reset button. But this is not the optimized way to do. Can somebody help me or give me an Idea to reset the game without loading the images again and again.
Many Thanks
are you sure that you are loading this textures into memory every time? if so, retain your textures before restart to be sure that it is not unloaded from CCTextureCache. loading textures into memory is the longest process.

SDL delete an image and replace it with the new one

I've started SDL just a few days ago and I'm having a problem
I tried to erase an image from the screen and replace it with the new one
here is my logic :
load image
apply surface, then delay for 1s
free old image surface (SDL_FreeSurface())
load new image
apply surface
The problem is the image is still there. (it didn't get erased, just stacked with the new image)
The screen doesn't work like you think it does. You cannot "delete" something from a screen buffer, you can only write new things to the screen buffer. To 'erase' something you need to write the "background" over it.
Some game loops just re-write the entire screen with the background every frame.
This probably belongs over at gamedev.stackexchange.com

DirectX 9 "Loading textures" progress bar

It doesn't need to look like a progress bar.
All I need it to say is "Loading images..." while the texture is loading, then saying "Done" when it's done loading.
I have no idea, how to do it?
I've done something like this in a DirectX application I was working on.
The idea behind it is to use the D3DXSPRITE interface to draw text to the screen. Begin drawing the scene with the Direct3D device, begin drawing with the sprite, call the sprite's DrawText function, and then end the sprite and the device scene.
NOTE: This requires that your Direct3D device and sprite be initialized before you start loading textures.
The way I did it was that I had a stack of Dialog/Popup objects that I drew to the screen every time my redraw function was called, so before I loaded the textures, I added a Dialog with the loading message, redrew the screen, then started loading, and then replaced/modified the dialog with the "Done!" message, and redrew again.
Hope it helps!