0

I am creating a game in cocos2D android. I need to have an alert at the end of my game. Can I do this in cocos2D android?

2 Answers 2

0

I think you should do this with JNI using the showMessageBoxJNI(const char * pszMsg, const char * pszTitle) method in the MessageJni.cpp class (in /cocos2dx/platform/android/jni). Simply import MessageJni.cpp in the class where you want to add an alert:

#include "./cocos2dx/platform/android/jni/MessageJni.h" // Note: this is a relative path, take care to the beginnin of the path "./" or "././" or etc..

showMessageBoxJNI("My alert message", "My alert title"); //Add this where you want in your class

Hope this helps.

0

Use menu for that. I think it is better option. on doing this, you can put click even to game over.when your game s over write below code

CCMenuItemFont item6 = CCMenuItemFont.item("Game over", this, "gameover");
            CCMenuItemFont.setFontSize(14);
            item6.setColor( new ccColor3B(0,0,0));
            CCMenu menu = CCMenu.menu(item6);
            menu.alignItemsVertically();
            addChild(menu);

and onclick of that menu this write below function. it will be called onclick.

public void gameover()
    {
        try {
            CCScene scene = nextlevellayer.scene();
            CCDirector.sharedDirector().pushScene(scene);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.