Cocos2d-x   发布时间:2022-05-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Cocos2d-x_CCTextFieldTTF输入框大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
//
// 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;
}

大佬总结

以上是大佬教程为你收集整理的Cocos2d-x_CCTextFieldTTF输入框全部内容,希望文章能够帮你解决Cocos2d-x_CCTextFieldTTF输入框所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。