// // 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("外部抬起"); }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。