您好,登錄后才能下訂單哦!
#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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。