Response keys for cocos2d-x in Android

Source: Internet
Author: User

1. Call in Layer:

Setkeypadenabled (true );

Override the following two methods in Layer:

Virtual void keybackclicked ();
Virtual void keymenuclicked ();

Void cbaselayer: keybackclicked ()
{
Int imanscenetag = ccdirector: shareddire()-> getrunningscene ()-> gettag (); // exit if the scenario is active.
If (main_scene_tag = imanscenetag)
{
Ccdirector: shareddirector ()-> end ();
# If (cc_target_platform = cc_platform_ios)
Exit (0 );
# Endif
}
}
Void cbaselayer: keymenuclicked ()
{

}

The above cbaselayer is the base class of all layers that need to respond to the Return key event, avoiding the need to write the same code for all layers.

2. You can also derive the subclass of cckeypaddelegate and register it as a delegate call for Keyboard Events.

Class mykeypaddelegate: Public cckeypaddelegate
{
Public:
Virtual void keybackclicked ();
Virtual void keymenuclicked ();
};

M_pkeypaddlegate = new mykeypaddelegate ();
Pdirector-> getkeypaddispatcher ()-> adddelegate (m_pkeypaddlegate );

In this way, you can respond to Keyboard Events globally.

Cclayer is also inherited from cckeypaddelegate

Reprinted from: http://blog.csdn.net/lamp_zy/article/details/8210303

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.