I’m trying to create a sprite with an image picked from gallery. The code works for iOS, but I get a black sprite in Android.
The image from gallery is saved into the “app dir”. This is the Java code:
The absolute path is passed to a native cpp code to create the sprite:
CCSprite *s = CCSprite::create(pngPath);
s->setPosition(whateverposition);
container->addChild(s);
The result is a black sprite. I have debugged the CCTextureCache and seems that the image is found ok in:
Hi Minggo. The image is there and looks ok. I attach it.
I have discovered this: After seen the black sprite, if I press the home button, and then, come back to my app, the image is displayed OK.
Could be anything related to gl-thread? I’m trying to mask the image picked from gallery and when I try to create a texture:
Yes, it was definitively a thread issue. I’m creating a clippingnode in response to a native call from java to cocos2dx. I’ve moved the code to a callfunc action an now works ok. Do you know if the native code is always called not in the main thread?
On Android, UI thread is different from gl thread. cocos2d-x run on gl thread. If you want to operate UI element, you should use Handler to do. And if an operation comes from UI thread, you should not invoke cocos2d-x codes through JNI directly. You can use Cocos2dxHelper.runOnGLThread() to do the operation on gl thread.
just for curiosity,
Did you add permission in manifest.xml <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> AFAIK this contains read permission too
Hi, thanks for your reply… but the problem I am facing is different… I am a newby so please bear with me.
I do not know how to pass the ImagePickerDelegate instance to pickImage().
How can I send this instance as parameter instead pickImage()