[Cocos2d-x]Cocos2d-x 3.2 學習筆記

來源:互聯網
上載者:User

擷取螢幕大小(Visible)

Size visibleSize = Director::getInstance()->getVisibleSize();Vec2 origin = Director::getInstance()->getVisibleOrigin();
列印調試(CCLOG)
CCLOG("Characters: %c %c", 'a', 65);CCLOG("Decimals: %d %ld", 1977, 650000L);CCLOG("Preceding with blanks: %10d", 1977);CCLOG("Preceding with zeros: %010d", 1977);CCLOG("Some different radixes: %d %x %o %#x %#o", 100, 100, 100, 100, 100);CCLOG("Floats: %4.2f %.0e %E", 3.1416, 3.1416, 3.1416);CCLOG("%s","A string");
建立菜單(Menu Item)
// 建立菜單auto menuItem = MenuItemImage::create( "MenuNormal.png",                                       "MenuSelected.png",                                       CC_CALLBACK_1(HelloWorld::menuCallback, this) );// 設定座標menuItem->setPosition( Vec2(x,y) );// 建立菜單auto menu = Menu::create(menuItem, NULL);menu->setPosition(Vec2::ZERO);this->addChild(menu, 1);
建立標籤(Label)
auto label = LabelTTF::create("Hello World", "Arial", 24);label->setPosition(Vec2(x,y));this->addChild(label, 1);
添加精靈(Sprite)
auto sprite = Sprite::create("Me.jpg");sprite->setPosition(Vec2(visibleSize.width / 2 , visibleSize.height / 2));sprite->setAnchorPoint(Vec2(0.5,0.5));this->addChild(sprite, 0);
精靈動畫(Action)
auto  actionBy = MoveBy::create(1, Point(100,100));auto  easeAction = EaseIn::create(actionBy, 2.5f);sprite->runAction(Repeat::create(easeAction, 5));
添加監聽(Listener)
auto listener1 = EventListenerTouchOneByOne::create();listener1->onTouchBegan = [](Touch* touch, Event* event){    auto target = static_cast<Sprite*>(event->getCurrentTarget());    Point locationInNode = target->convertToNodeSpace(touch->getLocation());    Size s = target->getContentSize();    Rect rect = Rect(0, 0, s.width, s.height);            if (rect.containsPoint(locationInNode))    {        log("sprite began... x = %f, y = %f", locationInNode.x, locationInNode.y);        target->setOpacity(180);        return true;    }    return false;};listener1->onTouchMoved = [](Touch* touch, Event* event){    auto target = static_cast<Sprite*>(event->getCurrentTarget());    target->setPosition(target->getPosition() + touch->getDelta());};listener1->onTouchEnded = [=](Touch* touch, Event* event){    auto target = static_cast<Sprite*>(event->getCurrentTarget());    if (target == sprite)    {        log("Click on the sprite");    }};_eventDispatcher->addEventListenerWithSceneGraphPriority(listener1, sprite);

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.