axmol/samples/Cpp/TestCpp/Classes/KeypadTest/KeypadTest.cpp

45 lines
1.0 KiB
C++
Raw Normal View History

#include "KeypadTest.h"
KeypadTest::KeypadTest()
{
auto s = Director::getInstance()->getWinSize();
auto label = LabelTTF::create("Keypad Test", "Arial", 28);
addChild(label, 0);
2013-07-12 14:11:55 +08:00
label->setPosition( Point(s.width/2, s.height-50) );
setKeypadEnabled(true);
// create a label to display the tip string
_label = LabelTTF::create("Please press any key...", "Arial", 22);
2013-07-12 14:11:55 +08:00
_label->setPosition(Point(s.width / 2, s.height / 2));
addChild(_label, 0);
_label->retain();
}
KeypadTest::~KeypadTest()
{
_label->release();
}
void KeypadTest::onKeyReleased(KeyboardEvent::KeyCode keycode, Event* event)
{
if (keycode == KeyboardEvent::KeyCode::KEY_BACKSPACE)
{
_label->setString("BACK clicked!");
}
else if (keycode == KeyboardEvent::KeyCode::KEY_MENU)
{
_label->setString("MENU clicked!");
}
}
void KeypadTestScene::runThisTest()
{
auto layer = new KeypadTest();
addChild(layer);
Director::getInstance()->replaceScene(this);
layer->release();
}