我在写一个cocos2dx 登录功能,
c++层点击游戏场景的“登录”按钮,调用java层的登录方法,
然后java层通过jni把登录结果返回给c++代码,
c++再跳到下一个场景。
每次jni跳转到下一个场景时,都会报错:
10-15 19:33:33.096: E/libEGL(810): call to OpenGL ES API with no current context (logged once per thread)
然后界面的菜单、sprite渲染不出来。
我google过了,在jni回调方法前,用Cocos2dxGLSurfaceView回调。
Cocos2dxGLSurfaceView.getInstance().queueEvent(new Runnable() {
@Override
public void run() {
JniCallback.nativeLoginSuccesCallback(arg0);
}
});
但是无效呀,还是会报这个错。
下一个场景的加载代码如下:
//添加背景
auto sprite = Sprite::createWithSpriteFrameName("background.png");
sprite->setAnchorPoint(Vec2(0,0));
this->addChild(sprite);
//创建登录Label
auto startGameLabel = LabelTTF::create("Start Game", "fonts/Marker Felt.ttf", 32);
startGameLabel->setColor(Color3B::WHITE);
auto startMenuItem = MenuItemLabel::create(startGameLabel,CC_CALLBACK_0(Welcome::runGame,this));
startMenuItem->setPosition(Vec2::ZERO);
//创建商店label
auto shopLabel = LabelTTF::create("Shop", "fonts/Marker Felt.ttf", 32);
shopLabel->setColor(Color3B::WHITE);
auto shopMenuItem = MenuItemLabel::create(shopLabel,CC_CALLBACK_1(Welcome::shop,this));
shopMenuItem->setPosition(Vec2(0,-startMenuItem->getContentSize().height));
auto menu = Menu::create(startMenuItem,shopMenuItem,NULL);
menu->setPosition(Vec2( visibleSize.width / 2,visibleSize.height / 2));
this->addChild(menu);
menu的字体都出不来..