//// HelloWorldScene.h//#ifndef __HELLOWORLD_SCENE_H__#define __HELLOWORLD_SCENE_H__#include "cocos2d.h"#include "cocos-ext.h"USING_NS_CC;USING_NS_CC_EXT;class HelloWorld : public cocos2d::cclayer{public: virtual bool init(); static cocos2d::CCScene* scene(); CREATE_FUNC(HelloWorld); voID touchDownAction(CCObject *pSender,CCControlEvent controlEvent); voID touchUpInsIDeAction(CCObject *pSender,CCControlEvent controlEvent); voID touchUpOutsIDeAction(CCObject *pSender,CCControlEvent controlEvent);};#endif
//// HelloWorldScene.cpp//#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; } cclabelTTF *ttf = cclabelTTF::create("未选中文字","MarkerFelt",25); CCScale9Sprite *bgSpr = CCScale9Sprite::create("button.png"); CCControlbutton *ccBtn = CCControlbutton::create(ttf,bgSpr); ccBtn->setposition(ccp(240,170)); ccBtn->setBackgroundSpriteForState(CCScale9Sprite::create("buttonHighlighted.png"),CCControlStateHighlighted); ccBtn->setTitlecolorForState(ccc3(255,0),CCControlStateHighlighted); ccBtn->setTitleForState(CCString::create("选中文字"),CCControlStateHighlighted); ccBtn->addTargetWithActionForControlEvents(this,cccontrol_selector(HelloWorld::touchDownAction),CCControlEventtouchDown); ccBtn->addTargetWithActionForControlEvents(this,cccontrol_selector(HelloWorld::touchUpInsIDeAction),CCControlEventtouchUpInsIDe); ccBtn->addTargetWithActionForControlEvents(this,cccontrol_selector(HelloWorld::touchUpOutsIDeAction),CCControlEventtouchUpOutsIDe); this->addChild(ccBtn); cclabelTTF *ttfBtnState = cclabelTTF::create("",25); ttfBtnState->setposition(ccp(240,220)); this->addChild(ttfBtnState,293); return true;}voID HelloWorld::touchDownAction(cocos2d::CCObject *pSender,CCControlEvent controlEvent){ cclabelTTF *ttf = (cclabelTTF *)this->getChildByTag(293); ttf->setString("按下");}voID HelloWorld::touchUpInsIDeAction(cocos2d::CCObject *pSender,CCControlEvent controlEvent){ cclabelTTF *ttf = (cclabelTTF *)this->getChildByTag(293); ttf->setString("内部抬起");}voID HelloWorld::touchUpOutsIDeAction(cocos2d::CCObject *pSender,CCControlEvent controlEvent){ cclabelTTF *ttf = (cclabelTTF *)this->getChildByTag(293); ttf->setString("外部抬起");}总结
以上是内存溢出为你收集整理的Cocos2d-x_CCControlButton(按钮类)介绍全部内容,希望文章能够帮你解决Cocos2d-x_CCControlButton(按钮类)介绍所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)