[Cocos2d-x] Cocos2d-x 3.2 Study Notes

Source: Internet
Author: User
Obtain the screen size (visible)
Size visibleSize = Director::getInstance()->getVisibleSize();Vec2 origin = Director::getInstance()->getVisibleOrigin();
Print debugging (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)
// Create menu auto menuitem = menuitemimage: Create ("menunormal.png", "menuselected.png", cc_callback_1 (helloworld: menucallback, this )); // set the coordinates menuitem-> setposition (vec2 (x, y); // create menu auto menu = menu: Create (menuitem, null ); menu-> setposition (vec2: zero); this-> addchild (menu, 1 );
Create a label)
auto label = LabelTTF::create("Hello World", "Arial", 24);label->setPosition(Vec2(x,y));this->addChild(label, 1);
Add 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));
Add 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);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.