Cocos2d-x_3.2 Demo ----------SpriteTest(2.2)

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   os   ar   for   div   

 1 class SpriteBatchNode1: public SpriteTestDemo 2 { 3 public: 4     CREATE_FUNC(SpriteBatchNode1); 5     SpriteBatchNode1(); 6     void addNewSpriteWithCoords(Vec2 p);// 根據新座標建立精靈 7     void onTouchesEnded(const std::vector<Touch*>& touches, Event* event);// 觸摸結束回調 8  9     virtual std::string title() const override;// 主標題10     virtual std::string subtitle() const override;// 副標題11 };

這個類和SpriteTest(2.1)的類差不多,只不過建構函式裡實現由差異,來看一下實現:

 1 SpriteBatchNode1::SpriteBatchNode1() 2 { 3     auto listener = EventListenerTouchAllAtOnce::create(); 4     listener->onTouchesEnded = CC_CALLBACK_2(SpriteBatchNode1::onTouchesEnded, this); 5     _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); 6  7     auto BatchNode = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 50);// 建立精靈集合對象 8     addChild(BatchNode, 0, kTagSpriteBatchNode); 9     10     auto s = Director::getInstance()->getWinSize();11     addNewSpriteWithCoords( Vec2(s.width/2, s.height/2) );12 }

上面函數裡面添加精靈集合對象,其他可以參考SpriteTest(2.1)。

 1 void SpriteBatchNode1::addNewSpriteWithCoords(Vec2 p) 2 { 3     auto BatchNode = static_cast<SpriteBatchNode*>( getChildByTag(kTagSpriteBatchNode) );// 根據標誌擷取節點 4      5     int idx = CCRANDOM_0_1() * 1400 / 100; 6     int x = (idx%5) * 85; 7     int y = (idx/5) * 121; 8      9 10     auto sprite = Sprite::createWithTexture(BatchNode->getTexture()/* 獲得紋理 */, Rect(x,y,85,121));// 從精靈集合類中擷取紋理11     BatchNode->addChild(sprite);12 13     sprite->setPosition( Vec2( p.x, p.y) );14 15     ActionInterval* action;16     float random = CCRANDOM_0_1();17     18     if( random < 0.20 )19         action = ScaleBy::create(3, 2);20     else if(random < 0.40)21         action = RotateBy::create(3, 360);22     else if( random < 0.60)23         action = Blink::create(1, 3);24     else if( random < 0.8 )25         action = TintBy::create(2, 0, -255, -255);26     else 27         action = FadeOut::create(2);28 29     auto action_back = action->reverse();30     auto seq = Sequence::create(action, action_back, nullptr);31     32     sprite->runAction( RepeatForever::create(seq));33 }
除了注釋的其他可以參考SpriteTest(2.1)。

Cocos2d-x_3.2 Demo ----------SpriteTest(2.2)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.