Android texture scaling bug and platform questions (cocos2d-2.0-rc2-x-2.0.1)

Hi,

I’m currently doing some game prototyping using cocos2d-2.0-rc2-x-2.0.1 and noticed a few things

  1. 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)
  1. 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.

Oren Bengigi wrote:

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( );
   }
}

About the playbook, im using cocos2d-x for playbook just fine…

in both bb10 (with the dev alpha) and playbook…

follow this link to more acurate help: http://www.cocos2d-x.org/projects/cocos2d-x/wiki/How_to_run_HelloWorld_and_Tests_on_BlackBerry_Tablet_OS
to create a new project in the workspace of momentics: http://cocos2d-x.org/projects/cocos2d-x/wiki/How_to_create_qnx_project_with_script
more on that: http://cocos2d-x.org/projects/cocos2d-x/wiki/How_to_build_project_by_using_bbndk10_and_bbndk20

@Martin:

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.

sergio migueis wrote:

About the playbook, im using cocos2d-x for playbook just fine…
>
in both bb10 (with the dev alpha) and playbook…
>
follow this link to more acurate help: http://www.cocos2d-x.org/projects/cocos2d-x/wiki/How_to_run_HelloWorld_and_Tests_on_BlackBerry_Tablet_OS
to create a new project in the workspace of momentics: http://cocos2d-x.org/projects/cocos2d-x/wiki/How_to_create_qnx_project_with_script
more on that: http://cocos2d-x.org/projects/cocos2d-x/wiki/How_to_build_project_by_using_bbndk10_and_bbndk20

Actually I just started to work on my game using the gles20 branch from github, it includes all scripts/samples to build for the BB targets :).

@Lance

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.

I’ve tested my code and it works. So I’ve uploaded my changes to github and created a pull request here:

Let me know if it helps.