分类: cocos2d-x 2013-04-08 16:32 2964人阅读 评论(1) 收藏 举报

新建工程,testInput

修改HelloWorldScene.h

#ifndef __HELLOWORLD_SCENE_H__

#define __HELLOWORLD_SCENE_H__

#include "cocos2d.h"

usingnamespace
cocos2d;

class HelloWorld :publiccocos2d::CCLayer,publiccocos2d::CCTextFieldDelegate

{

public:

// Method 'init' in cocos2d-x returns bool, instead of 'id' in cocos2d-iphone (an object pointer)

virtual
bool init();

// there's no 'id' in cpp, so we recommend to return the class instance pointer

static
cocos2d::CCScene* scene();

//重写CCTextFieldDelegate的回调函数

//当用户启动虚拟键盘时的回调函数

virtual
bool onTextFieldAttachWithIME(CCTextFieldTTF *pSender);

//当用户关闭虚拟键盘时的回调函数

virtual
bool onTextFieldDetachWithIME(CCTextFieldTTF *pSender);

//当用户进行输入时的回调函数

virtual
bool onTextFieldInsertText(CCTextFieldTTF *pSender,constchar *text,int nLen);

//当用户删除文字时的回调函数

virtual
bool onTextFieldDeleteBackward(CCTextFieldTTF *pSender,constchar *delText,int nLen);

// preprocessor macro for "static create()" constructor ( node() deprecated )

CREATE_FUNC(HelloWorld);

};

#endif // __HELLOWORLD_SCENE_H__

修改HelloWorldScene.cpp

#include "HelloWorldScene.h"

#include "SimpleAudioEngine.h"

usingnamespace
cocos2d;

usingnamespace
CocosDenshion;

CCScene* HelloWorld::scene()

{

// 'scene' is an autorelease object

CCScene *scene =
CCScene::create();

// 'layer' is an autorelease object

HelloWorld *layer =HelloWorld::create();

// add layer as a child to scene

scene->addChild(layer);

// return the scene

return scene;

}

// on "init" you need to initialize your instance

boolHelloWorld::init()

{

//////////////////////////////

// 1. super init first

if ( !CCLayer::init() )

{

return
false;

}

/////////////////////////////

// 2. add a menu item with "X" image, which is clicked to quit the program

//    you may modify it.

CCSize size=CCDirector::sharedDirector()->getWinSize();

CCTextFieldTTF *textField = CCTextFieldTTF::textFieldWithPlaceHolder("点出输入...","Helvetica",
);

textField->setPosition(ccp(size.width*0.5, size.height*0.7));

addChild(textField);

//绑定接口

textField->setDelegate(this);

//开启输入

textField->attachWithIME();

//关闭输入

//textField->detachWithIME();

return
true;

}

//当用户启动虚拟键盘时的回调函数

bool HelloWorld::onTextFieldAttachWithIME(CCTextFieldTTF *pSender)

{

CCLOG("启动输入");

//return false;

//return true:不启动

}

//当用户关闭虚拟键盘时的回调函数

bool HelloWorld::onTextFieldDetachWithIME(CCTextFieldTTF *pSender)

{

CCLOG("关闭输入");

return
false;

//return true:不关闭

}

//当用户进行输入时的回调函数

bool HelloWorld::onTextFieldInsertText(CCTextFieldTTF *pSender,constchar
*text,int nLen)

{

CCLOG("输入字符...");

return
false;

//return true:不会输入进字符

}

//当用户删除文字时的回调函数

bool HelloWorld::onTextFieldDeleteBackward(CCTextFieldTTF *pSender,constchar
*delText,int nLen)

{

CCLOG("删除字符");

return
false;

//return true:不删除

}

源码地址:http://download.csdn.net/detail/cloud95/5234145

(转) CCTextFieldTTF输入框的更多相关文章

  1. 传智播客C++第五期培训视频教程免费下载

    C/C++的应用领域几乎无处不在,服务器,嵌入式,物联网,移动互联网,信息安全,游戏,基本上大小通吃.C/C++市场份额高达26%,也就是每四个程序员就有一个C/C++程序员.市场需求量非常大,而且工 ...

  2. Cocos2d-x学习笔记(9)(CCTextFieldTTF使用输入框)

    1.CCTextFieldTTF创建和使用 CCTextFieldTTF::create(const char* placeholder,const char* fontName.float font ...

  3. cocos2dx注册场景 使用CCEditBox实现输入框

    我们在开始玩一个游戏时,通常要做的第一件事就是注册账号,下面就让我们来制作一个简单的注册场景,我所使用的cocos2dx版本为2.2.2 在这个场景中最主要的元素就是输入框和按钮,我从网上找了一些素材 ...

  4. cocos2d-x 聊天输入框实现

    转自:http://bbs.9ria.com/thread-216948-1-10.html 聊天输入框  (单行输入框 ,多行可自己扩展) 实现功能: 1.普通输入 2.设置输入框显示最大宽度(PT ...

  5. Cocos2d-x CCEditBox & CCTextFieldTTF

    下面简单记录一下如何Cocos2d-x中创建输入编辑框.在引擎中为我们提供了这样两个类:CCEditBox  和  CCTextFieldTTF. 一.CCEditBox ①这个类文件的位置 ②这个类 ...

  6. cocos2dx CCTextFieldTTF

    CCTextFieldTTF是一个提供文本输入的控件. 先上个简单的例子 CCSize size = __winSize; CCTextFieldTTF* textEdit = CCTextField ...

  7. cocos2d-x 输入框CCEditBox的使用

    特别说明: 这个版本的CCEditBox,设计有缺陷,背景图片的位置与输入区域的位置不同步,需要自己修改原来的代码,自己加上输入区域的坐标偏移量. void CCEditBox::setPositio ...

  8. Android点击列表后弹出输入框,所点击项自动滚动到输入框上方

    使用微信的朋友圈会发现,点击某一条评论后输入框会弹出来,然后所点击的那一项会自动地滚动到输入框上方的位置,这样如果开始所点击的评论在屏幕很下方的话,就不会被输入框遮住,虽然微信这一点在我的MX2频繁点 ...

  9. Bootstrap3系列:输入框组

    1. 基本实例 通过在文本输入框 <input> 前面.后面或是两边加上文字或按钮,实现对表单控件的扩展. .input-group包含.input-group-addon给 .form- ...

随机推荐

  1. 获取到body的offsetTop和offsetLeft值

    function offsetTL(obj){//获取到body的offsetTop和offsetLeft var t=0,l=0; while(obj){ t=t+obj.offsetTop; l= ...

  2. bzoj4457: 游戏任务--双层01背包

    这题和NOIP的金明的预算方案(?)很像,只不过附件的数量增多了 如果对主件进行一次01背包,再套一层附件的01背包O(n4)肯定会爆.. 所以我们可以先预处理出,对于每个主件,花的时间为k的情况下, ...

  3. spidermark sensepostdata ntp_monlist.py

    试NTP 时间服务器用的,ntp_ip_enum.py,源码如下:#!/usr/bin/env python"""Basic script to pull address ...

  4. IOS第18天(9,核心动画-动画组)

    ****动画组 // 核心动画都是假象,不能改变layer的真实属性的值// 展示的位置和实际的位置不同.实际位置永远在最开始位置 #import "HMViewController.h&q ...

  5. 【iCore3 双核心板_FPGA】例程二:GPIO输出实验——点亮三色LED

    实验指导书及代码包下载: http://pan.baidu.com/s/1boiOJBT iCore3 购买链接: https://item.taobao.com/item.htm?id=524229 ...

  6. 文件上传去除"Content-Disposition: form-data"

    某个项目中为了统一处理文件上传业务,创建了一个FileUpload Handle,由于上传客户端用到各种技术,当时为了方便断点续传,就直接接收请求中的文件内容(可能是分片),所以处理的不是规范的htt ...

  7. 针对ajax执行后swiper特效无法执行解决方案

    ajax执行后重新绑定swiper事件.

  8. WINFORM 打开PDF

    这里使用 Adobe Read 组件 的方式 首先电脑上需要安装AdobeRead VS中添加COM引用 再在工具选项卡中添加Adobe PDF Read 组件即可 从工具箱中直接拖动组件到窗体中即可

  9. lsof 命令 系统管理 系统监控

    lsof(list open files)是一个列出当前系统打开文件的工具.在linux环境下,任何事物都以文件的形式存在,通过文件不仅仅可以访问常规数据,还可以访问网络连接和硬件. 在终端下输入ls ...

  10. deleteRow

    如果是删除某一行的话,直接delete就可以,行数要在删除之前剪掉,否则会崩溃. 但是,如果section要减一的话,是不能删掉section的 Terminating app due to unca ...