溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

cocos2d點擊button,輸出Log

發(fā)布時間:2020-06-18 10:42:28 來源:網(wǎng)絡(luò) 閱讀:875 作者:584851044 欄目:開發(fā)技術(shù)
 #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");
}

向AI問一下細節(jié)

免責(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)容。

AI