In my game, I want add loading scene because it takes more than 10 second for load game images and create image file in android sdcard.
so I use addImageAsync. but callfuncO_selector method did not called. and print out below log message…
JniHelper(18494): Failed to get the environment using GetEnv()
what can I do for this problem? it works on WIN32 platform but didn’t on Android…
Add my code that problem part. the problem is didn’t call method imageLoaded().
// class JS_Main : public cocos2d::CCLayerColor
void JS_Main::onEnter()
{
.
.
.
// load and create image
scheduleOnce(schedule_selector(JS_Main::loadPieces), 0.5f);
}
void JS_Main::loadPieces(float dt)
{
.
.
.
for(int idx=0; idx<m_NumberOfImages; idx++) {
.
.
.
CCTextureCache::sharedTextureCache()->addImageAsync(szPiece,this, callfuncO_selector(JS_Main::imageLoaded));
}
}
void JS_Main::imageLoaded(CCObject* pObj)
{
CCLog(“JS_Main :: Image imageLoaded Index : %d”, m_nPieceIndex);
CCTexture2D* pTexture = (CCTexture2D**)pObj;
CCDirector**director = CCDirector::sharedDirector();
//CCAssert( [NSThread currentThread] [director runningThread], @“FAIL. Callback should be on cocos2d thread”);
// IMPORTANT: The order on the callback is not guaranteed. Don't depend on the callback
// This test just creates a sprite based on the Texture
JS\_Block\* pBlock = NULL;
pBlock = JS\_Block::JS\_BlockWithTexture(pTexture, this);
pBlock-\>setTextureRect(m\_Puz[m\_nGameLevel][m\_nPieceIndex].rcFit);
// Anchor point
pBlock-\>setAnchorPoint(m\_Puz[m\_nGameLevel][m\_nPieceIndex].ptAnchor);
pBlock-\>setScale(0.5f);
pBlock-\>setCanMoveRect(RC\_RIGHT\_BG); // 이동가능한 우측영역
addChild(pBlock, 100+m\_nPieceIndex, 100+m\_nPieceIndex);
m\_nPieceIndex++;
if ( m\_tc m\_nPieceIndex )
{
CCLog(“JS_Main :: Image imageLoaded Index END”);
m_pWait~~>stopActionByTag;
m_pWait~~>setVisible(false);
shufflePuzzle();
setKeypadEnabled(true);
}
CCLog(“JS_Main :: Image loaded END”);
}
Thanks for reading. Have a nice day.