Cocos2dx Android exit prompt dialog box

Source: Internet
Author: User

Many games will be prompted "Do you want to quit the game when you press the Back button to exit?" "And then there are two buttons for" OK "and" back ", in general,

Using the Android Bottom-up dialog is the best choice to block other touch events on the screen.

Using Eclipse to open the Cocos Project, under the Org.cocos2dx.lib package, there is a Cocos2dxglsurfaceview.java class with a

onkeydown function to respond to keyboard events, under Keyevent.keycode_back, add a Code Implementation dialog box pops up:

Alertdialog.builder Builder = new Alertdialog.builder (Cocos2dxactivity.getcontext ());

Builder.setmessage ("OK exit?") ");

Builder.settitle ("Hint:");

Builder.setpositivebutton ("OK", new Dialoginterface.onclicklistener () {

@Override

public void OnClick (dialoginterface arg0, int arg1) {

Arg0.dismiss ();

System.exit (0);

}

});

Builder.setnegativebutton ("Cancel", new Dialoginterface.onclicklistener () {

@Override

public void OnClick (dialoginterface arg0, int arg1) {

Arg0.dismiss ();

}

});

Builder.create (). Show ();

The implementation principle is very simple, more dialog box implementation can refer to the following links, http://www.oschina.net/question/157182_51417

Reprint please indicate the source, from the blog Park Hemjohn

Cocos2dx Android exit prompt dialog box

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.