Cocos2d-x_CCTextFieldTTF输入框
发布时间:2020-12-14 19:08:26 所属栏目:百科 来源:网络整理
导读://// HelloWorldScene.h//#ifndef __HELLOWORLD_SCENE_H__#define __HELLOWORLD_SCENE_H__#include "cocos2d.h"USING_NS_CC;class HelloWorld : public cocos2d::CCLayer,public cocos2d::CCTextFieldDelegate{public: virtual bool init(); static cocos2d:
// // HelloWorldScene.h // #ifndef __HELLOWORLD_SCENE_H__ #define __HELLOWORLD_SCENE_H__ #include "cocos2d.h" USING_NS_CC; class HelloWorld : public cocos2d::CCLayer,public cocos2d::CCTextFieldDelegate { public: virtual bool init(); static cocos2d::CCScene* scene(); void menuCloseCallback(CCObject* pSender); CREATE_FUNC(HelloWorld); virtual bool onTextFieldAttachWithIME(CCTextFieldTTF *pSender); virtual bool onTextFieldDetachWithIME(CCTextFieldTTF *pSender); virtual bool onTextFieldInsertText(CCTextFieldTTF *pSender,const char *delText,int nLen); virtual bool onTextFieldDeleteBackward(CCTextFieldTTF *pSender,int nLen); }; #endif <pre name="code" class="cpp">// // HelloWorldScene.h // #include "HelloWorldScene.h" USING_NS_CC; CCScene* HelloWorld::scene() { CCScene *scene = CCScene::create(); HelloWorld *layer = HelloWorld::create(); scene->addChild(layer); return scene; } bool HelloWorld::init() { if ( !CCLayer::init() ) { return false; } CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCTextFieldTTF *textField = CCTextFieldTTF::textFieldWithPlaceHolder("点击输入...","Helvetica",24); textField->setPosition(ccp(visibleSize.width*0.5,visibleSize.height*0.7)); textField->setDelegate(this); textField->attachWithIME(); this->addChild(textField); return true; } // CCTextFieldTTFDelegate bool HelloWorld::onTextFieldAttachWithIME(CCTextFieldTTF *pSender) { CCLog("启动输入"); return false; } bool HelloWorld::onTextFieldDetachWithIME(CCTextFieldTTF *pSender) { CCLog("关闭输入"); return false; } bool HelloWorld::onTextFieldInsertText(CCTextFieldTTF *pSender,const char *text,int nLen) { CCLog("输入字符"); return false; } bool HelloWorld::onTextFieldDeleteBackward(CCTextFieldTTF *pSender,int nLen) { CCLog("删除字符"); return false; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |