Some times textures disappear from sprites. I have a sprite that appears with white color and it should have a texture on it and a label that should have a text in it an it appears with black color. The labels are subclasses of sprite so this problem is related to Sprites. Could some one tell me what is the problem ? Did some one meet this bug to in Cococs2D on Android ? Thank's !
I had such a problem when I was doing navigation from "outside" of cocos2d i.e. i relied on Android's native back button's callback to change scenes. Apparently this callback doesn't work on the same thread as cocos and causes this problem (maybe something with WeakReferences in the TextureCache). Hope it helps :)
Are you using pvr? When I tried using pvr I was getting what sounds like the same issues. I switched to png and it fixed the problem for me.
Related
I have a C/C++ MFC application where a moving image from left to right displays with StretchDIBits in a window. And the screen tearing happens in the window.
Please understand I am not talking about flickering but screen tearing as flickering is more like whole screen blinking while screen tearing causes some scattering part of the image not synchronized when the image moves to right or left so that a moving vertical line temporarily looks broken one in a very short period of time.
At first, I thought StretchDIBits was the cause but changing it to SetDIBitsToDevice didn't help at all. So I am suspecting it's GDI and googling about it supported my doubt.
I saw this article to fix the problem but it'd be cleaner to directly use DirectX in my opinion.
So at this point, I am thinking about using DirectX or OpenGL to prevent this tearing but not sure if this approach will work or if there is any better approach. So my question is
Would going with OpenGL or DirectX solve this problem?
Is there any better approach than going with OpenGL and DirectX?
Any clue will be appreciated.
To save time, please don't recommend not to use MFC as this is one of the requirements.
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.
I'm wanting to create a WoW cooldown effect where a player does some action and is not able to do the action again until the sprite is fully shown again. I have a grayed out version of the same sprite and am wanting to slowly reveal the sprite until it is fully available again. So, there will be a slow blend vertically of the gray and colored sprite.
Is there a way to do this with built in functionality with Cocos2d and CCSprite?
I'm using v2 of Cocos2d so I could write a shader which I think would be pretty easy, but before I went this route I wanted to see if there is an easier way.
Take a look to the CCProgressTimer class. If I understand right, it will make what you want
You can use CCFadeIn to animate the colored sprite over the grayed sprite :
[coloredSprite runAction:[CCFadeIn actionWithDuration:1.0f];
My game needs to implement night vision effect. I'm using a CCRenderTexture as a mask, and I plan to draw the visible areas onto the mask by using [rangeSprite visit];
However, it need GL_SUBTRUCT mode. I searched cocos2d's codes, but found nowhere the macro is used. Does it mean cocos2d do not support this?
Have you solved this? I have the same problem, and am approaching it currently by using a blendmode like this:
[light setBlendFunc:ccBlendFuncMake(GL_DST_ALPHA, GL_ZERO)];
...whereas light is a sprite I paint onto my CCRenderTexture, which gets laid over the screen.
I read a topic on OpenGL.org where a guy made this:
http://coreytabaka.com/programming/cube-demo/
He said to release the source code but he never did,
does anyone how I could get the same idea?
Has to do with clearing the window with alpha but drawing
on it as well.. just don't get how to get OpenGL setup like
that. From there I can do my stuff but I'd like a base for
this running in C++ with VisualStudio,
Anybody has something like this laying around ? Or can show
pieces of the code to get this kind of rendering done.
Render the 3d scene to a pbuffer.
Use a color key to blend the pbuffer to screen.