I’m currently doing some game prototyping using cocos2d-2.0-rc2-x-2.0.1 and noticed a few things
Android texture bug
I’m trying to make a small game that uses the pixelated look. In my game I’m using a 180x60 px image that is scaled times five its original size. To make sure it is scaling nicely, I’m using this method on the sprite: *pSprite~~>getTexture~~>setAliasTexParameters;*
On Windows this seems to work just fine. When I try it on my Android Phone it works alright when the application/scene is launched the first time. If you pause the application by pressing home and continue it, for some reason the sprites get blurry .
h3. Screenshots Android screenshot: Initial state
Android screenshot: After resuming
h3. My code
<pre>
bool ForegroundLayer::init
{
bool bRet = false;
do
{
// Init super first.
CC_BREAK_IF);
// ask director the window size
CCSize size = CCDirector::sharedDirector~~>getWinSize;
// add Load sprite
CCSprite* pSprite = CCSprite::create;
// position the sprite on the center of the screen
pSprite~~>setPosition );
// Disable anti-aliasing
pSprite~~>getTexture~~>setAliasTexParameters;
// Set scale
pSprite~~>setScale;
// add the sprite as a child to this layer
this~~>addChild(pSprite, 0);
bRet = true;
} while (0);
return bRet;
}
Any clue why this behavior happens? (I can force it to draw properly by calling setAliasTexParameters() in an update callback, but I rather avoid that hack)
BlackBerry platform
I know release cocos2d-2.0-rc2-x-2.0.1 is a release candidate, but I was wondering why there are no files included for the BlackBerry playbook/bb10 platforms? I tried to find the source code on Github, but I could not figure out which repo is containing this release.
The gles20 branch seems to use a very different directory structure
The master branch does include all blackberry scripts but I guess that its still the 1.x branch?
When resuming on Android, the App reloads all of the texture due to EGL context lost.
So it reloads the textures with the default settings.
So you need to call setAliasTexParameters() on that texture after it is reloaded.
I’m not sure exactly were you can put the code to reload it.
When resuming on Android, the App reloads all of the texture due to EGL context lost.
So it reloads the textures with the default settings.
So you need to call setAliasTexParameters() on that texture after it is reloaded.
I’m not sure exactly were you can put the code to reload it.
Thanks for the explanation Oren, seems like I will need to add an extra callback to notify the class that the texture properties need to be reloaded.
I have exactly the same problem, if you find a nice place to put the code please let me know. Ideally cocos2d should be able to cache the settings and put them back on after reload but if there is a callback which tells us when we need to apply the settings that would work too.
You could try to put a check in the sprite’s or the layer’s update methods. Something like this:
// Use layerUpdate( ) instead of update( ) for your own stuff and make a
// schedule to run this layer per frame.
void Layer::layerUpdate( ) {
if ( pSprite -> getTexture( ) -> getAliasTexParameters( ) != ) { // Not real code, I just invented it. It might not exist.
pSprite -> getTexture( ) -> setAliasTexParameters( );
}
}
I haven’t yet figured out a reliable way to do such thing. For my other Android project I’ve been using openFrameworks. That framework provides a method called “reloadTextures()” which is only called when an app resumes. In my case I will probably just modify the java/jni code a bit to make it inform the app it should set the texture properties again.
Well, yes but it wouldn’t be much better than just calling setAliasTexParameters every frame. And there isn’t a getAliasTexParameters method anyway.
I’ve had a bit of dig around the cocos2d-x source code and doesn’t look like it exposes any kind of callback for when the EGL context is lost. I’ve started writing some code to store the texParams inside VolatileTexture when you set them, then it restores them after it reloads the textures. I’ll post the changes once I’m done testing them if you’re interested. Would be good to get it into the main branch so people don’t need to worry about it.