#include "HelloWorldScene.h" #include "MyLayer.h" using namespace cocos2d; CCScene* HelloWorld::scene() { CCScene * scene = NULL; do { // 'scene' is an autorelease object //定义场景 scene = CCScene::create(); CC_BREAK_IF(! scene); // 'layer' is an autorelease object //定义图层 HelloWorld *layer = HelloWorld::create(); CC_BREAK_IF(! layer); // add layer as a child to scene //为场景添加图层 scene->addChild(layer); } while (0); // return the scene return scene; } // on "init" you need to initialize your instance bool HelloWorld::init() { bool bRet = false; do { ////////////////////////////////////////////////////////////////////////// // super init first ////////////////////////////////////////////////////////////////////////// CC_BREAK_IF(! CCLayer::init()); //定义图片 CCScale9Sprite *nineGile = CCScale9Sprite::create("CloseNormal.png"); CCScale9Sprite *nineGileDown = CCScale9Sprite::create("HelloWorld.png"); //定义文件标题 CCLabelTTF *title = CCLabelTTF::create("Touch Me !","Marker Felt",30); //定义一个按钮,将按钮与图片和文字绑定 CCControlButton *contrl = CCControlButton::create(title,nineGileDown); //定义一个鼠标点击事件,调用回调函数 contrl->addTargetWithActionForControlEvents(this,cccontrol_selector(HelloWorld::touchDown),CCControlEventTouchDown); contrl->setPosition(ccp(200,200)); this->addChild(contrl); // nineGile->setContentSize(CCSize(50,50)); // this->addChild(nineGile); bRet = true; } while (0); return bRet; } void HelloWorld::touchDown(CCObject*pObject,CCControlEvent event) { //回调函数输出log CCLOG("Touch Down"); }
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。