2012-05-02 33 views
2

我想在jni main.cpp中訪問我的場景,但是當我撥打cocos2d::CCDirector::sharedDirector()->getRunningScene()時,我無法得到它! 我的代碼:在jni main.cpp中訪問運行場景(cocos2d-x)

void Java_tehrannama_test_tehrannama2_zoomIn(JNIEnv* env, jobject thiz,jfloat s) { 

__android_log_print(ANDROID_LOG_DEBUG, "zoom1", "zooom"); 
    HelloWorld* helloworld = dynamic_cast<HelloWorld*>(cocos2d::CCDirector::sharedDirector()->getRunningScene()); 
    helloworld->zoomin(s); 
    helloworld->center.x = helloworld->center.x -10000; 
} 

我沒有其他的場景,然後爲HelloWorld。

+0

我可以知道你爲什麼要這樣做? –

+0

我想使用sdk ui並在我的cocos2d-x代碼和java代碼之間進行交互。 – Ocelot

回答

2

我發現問題其實我的錯誤!我的helloworld圖層添加爲當前場景的孩子,解決的辦法是在添加時標記helloworld,然後獲取它:

HelloWorld* helloworld = dynamic_cast<HelloWorld*>(cocos2d::CCDirector::sharedDirector()->getRunningScene()->getChildByTag(1));