您好,登錄后才能下訂單哦!
#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"); //定義文件標(biāo)題 CCLabelTTF *title = CCLabelTTF::create("Touch Me !","Marker Felt",30); //定義一個按鈕,將按鈕與圖片和文字綁定 CCControlButton *contrl = CCControlButton::create(title,nineGileDown); //定義一個鼠標(biāo)點擊事件,調(diào)用回調(diào)函數(shù) 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) { //回調(diào)函數(shù)輸出log CCLOG("Touch Down"); }
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。