91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

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

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

[cocos2d-x]HelloWorldDemo

發布時間:2020-07-30 11:27:07 來源:網絡 閱讀:281 作者:蓬萊仙羽 欄目:游戲開發

實現一個demo,具備以下功能:

1.讓幾個字分別位于中間和四個角落。

2.中間的字體改變,并且帶有閃爍功能。

3.單點觸摸和多點觸摸,并且能夠實現滑動效果,滑動的話必須使用帶有bool返回值的單點觸摸設置為true。

4.下面兩個按鈕能夠實現添加節點和移除節點的作用。

效果圖:

[cocos2d-x]HelloWorldDemo

實現代碼:

HelloWorldScene.h:

#ifndef __HELLOWORLD_SCENE_H__ #define __HELLOWORLD_SCENE_H__  #include "cocos2d.h" using namespace cocos2d; class HelloWorld : public cocos2d::CCLayer { public:     // Method 'init' in cocos2d-x returns bool, instead of 'id' in cocos2d-iphone (an object pointer)     virtual bool init();      // there's no 'id' in cpp, so we recommend to return the class instance pointer     static cocos2d::CCScene* scene();          // a selector callback     void menuCloseCallback(CCObject* pSender);      // preprocessor macro for "static create()" constructor ( node() deprecated )     CREATE_FUNC(HelloWorld);      void menuRemoveCallback(CCObject* pSender);      //啟動觸屏事件     virtual void ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent);      //觸摸注冊事件     virtual void registerWithTouchDispatcher();      //單點觸摸事件     virtual bool ccTouchBegan(CCTouch *pTouch,CCEvent *pEvent);      //移動事件     virtual void ccTouchMoved(CCTouch *pTouch,CCEvent *pEvent); };  #endif // __HELLOWORLD_SCENE_H__

HelloWorldScene.cpp:

#include "HelloWorldScene.h" #include "SimpleAudioEngine.h"  using namespace cocos2d; using namespace CocosDenshion;  CCScene* HelloWorld::scene() {     // 'scene' is an autorelease object     CCScene *scene = CCScene::create();          // 'layer' is an autorelease object     HelloWorld *layer = HelloWorld::create();      // add layer as a child to scene     scene->addChild(layer);      // return the scene     return scene; }   bool HelloWorld::init() {      if ( !CCLayer::init() )     {         return false;     }     //設置當前允許觸摸     this->setTouchEnabled(true);          CCMenuItemImage *pCloseItem = CCMenuItemImage::create(                                         "CloseNormal.png",                                         "CloseSelected.png",                                         this,     menu_selector(HelloWorld::menuCloseCallback) );     pCloseItem->setPosition( ccp(CCDirector::sharedDirector()->getWinSize().width / 2- 30, 20) );      CCMenuItemImage *pCloseItem1 = CCMenuItemImage::create(                                                           "CloseNormal.png",                                                           "CloseSelected.png",                                                           this,                                                           menu_selector(HelloWorld::menuRemoveCallback) );     pCloseItem1->setPosition( ccp(CCDirector::sharedDirector()->getWinSize().width / 2  + 30, 20) );               CCMenu* pMenu = CCMenu::create(pCloseItem1,pCloseItem, NULL);     pMenu->setPosition( CCPointZero );     this->addChild(pMenu, 1);          CCLabelTTF* pLabel = CCLabelTTF::create("江蘇理工", "Thonburi", 34);     CCSize size = CCDirector::sharedDirector()->getWinSize();     //一開始設置為綠色     pLabel->setColor(ccGREEN);     pLabel->setPosition( ccp(size.width / 2, size.height / 2) );     this->addChild(pLabel,1);          //讓節點閃爍的方法     CCAction *action = CCBlink::create(5, 20);     pLabel->runAction(action);     //變色的方法     CCAction *action1 = CCTintTo::create(5, 255, 0, 0);     pLabel->runAction(action1);          //左上角顯示姓名     CCLabelTTF* pLabel1 = CCLabelTTF::create("丁小未", "Thonburi", 34);     CCSize size1 = CCDirector::sharedDirector()->getWinSize();     pLabel1->setAnchorPoint(ccp(0, 1));     pLabel1->setPosition( ccp(0, size1.height) );     this->addChild(pLabel1,1);          //右上角顯示性別     CCLabelTTF* pLabel2 = CCLabelTTF::create("男", "Thonburi", 34);     CCSize size2 = CCDirector::sharedDirector()->getWinSize();     pLabel2->setAnchorPoint(ccp(1, 1));     pLabel2->setPosition( ccp(size2.width, size2.height) );     this->addChild(pLabel2,1);          //右下角顯示年齡     CCLabelTTF* pLabel3 = CCLabelTTF::create("23", "Thonburi", 34);     CCSize size3 = CCDirector::sharedDirector()->getWinSize();     pLabel3->setAnchorPoint(ccp(1, 0));     pLabel3->setPosition( ccp(size3.width, 0) );     this->addChild(pLabel3,1);     return true;      }  void HelloWorld::menuCloseCallback(CCObject* pSender) {     //結束關閉事件 //    CCDirector::sharedDirector()->end(); // //#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) //    exit(0); //#endif     CCSize size = CCDirector::sharedDirector()->getWinSize();          CCLabelTTF *pLabel = CCLabelTTF::create("我是添加的", "Thonburi", 24);     pLabel->setPosition(ccp(size.width/2+30,size.height/2+30));     pLabel->setTag(10);     this->addChild(pLabel,1); }  void HelloWorld::menuRemoveCallback(CCObject *pSender) {     CCNode *pLabel = this->getChildByTag(10);     this->removeChild(pLabel); }  //多點觸摸方法 void HelloWorld::ccTouchesBegan(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent) {     //添加子視圖     //隨機數是CCRANDOM_0_1,是產生0-1之間的隨機數 //    CCSize size = CCDirector::sharedDirector()->getWinSize(); //    CCLabelTTF *pLabel = CCLabelTTF::create("觸屏添加", "Thonburi", 24); //    pLabel->setPosition(ccp(100, 100)); //    pLabel->setTag(10); //    this->addChild(pLabel,1);     CCLog("多點觸摸Began"); }  bool HelloWorld::ccTouchBegan(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent) {     CCLog("單點觸摸");     return true;//如果這個不返回true的話,則move方法沒用 }  void HelloWorld::ccTouchMoved(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent) {     CCLog("單點moved"); }  //觸摸注冊事件 //如果沒有這個,默認的是多點觸摸,Targeted是單點,Standed是多點觸摸 void HelloWorld::registerWithTouchDispatcher() {     CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 0, true); }


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

扎鲁特旗| 葫芦岛市| 锡林郭勒盟| 祁门县| 宁海县| 平遥县| 石阡县| 来宾市| 哈尔滨市| 宜兰市| 马鞍山市| 互助| 仙游县| 青龙| 集安市| 周宁县| 璧山县| 元谋县| 堆龙德庆县| 抚顺市| 五莲县| 衡山县| 米易县| 大邑县| 奉化市| 辛集市| 云龙县| 汝南县| 环江| 红原县| 乐陵市| 和平区| 微博| 合山市| 满城县| 安顺市| 化德县| 新津县| 志丹县| 乌拉特前旗| 石门县|