Cocos2d-x Study Notes (12) 3D Effects

Source: Internet
Author: User

The special effect class is the gridaction class, which is actually a grid-based 3D effect class. You need to enable OpenGL depth buffering, otherwise 3D distortion is easy.

Below is an snippet, which creates a Grid Object and adds it to the current layer. At the same time, it adds the object for 3D effects to the grid object.

        gridNodeTarget = NodeGrid::create();    addChild(gridNodeTarget);// add to current layer    auto bg = Sprite::create("background.png");    bg->setPosition(Vec2(visibleSize.width/2, visibleSize.height /2));    gridNodeTarget->addChild(bg);    sprite = Sprite::create("hero.png");    sprite->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2));    gridNodeTarget->addChild(sprite);
View code

Below is the use of the 3D special effects class, and the effect will not be displayed here.

Void myaction: gomenu (ref * psender) {size visiblesize = Director: getinstance ()-> getvisiblesize (); log ("tag = % I ", this-> gettag (); Switch (this-> gettag () {Case kflipx3d: // X axis 3D flip, the parameter is duration gridnodetarget-> runaction (flipx3d :: create (3.0f); break; Case kpageturn3d: // page flip effect. The first parameter is duration, and the second parameter is grid size gridnodetarget-> runaction (pageturn3d :: create (3.0f, size (15, 10); break; Case klens3d: // convex lens effect. The first parameter is duration, and the second parameter is grid size, the third parameter is the lens center, and the fourth parameter is the lens radius gridnodetarget-> runaction (lens3d: Create (3.0f, size (), vec2 (visiblesize. width/2, visiblesize. height/2), 240); break; Case kshaky3d: // special shaking effect. The first parameter is the duration parameter. The first parameter is the grid size, and the third parameter is the shaking range, the fourth parameter is gridnodetarget-> runaction (shaky3d: Create (3.0f, size (15,10), 5, false); break; Case kwaves3d: // 3D fluctuation effect, the first parameter is duration, the second parameter is grid size, the third parameter is the number of fluctuations, and the fourth parameter is the amplitude gridnodetarget-> runaction (waves3d: Create (3.0f, size (),); break; Case kjumptiles3d: // 3D tile beating effect. The first parameter is duration, and the second parameter is grid size, the third parameter is the number of times, and the fourth parameter is the amplitude gridnodetarget-> runaction (jumptiles3d: Create (3.0f, size (),); break; Case kshakytiles3d: // 3D tile shaking effect. The first parameter is duration, the second parameter is grid size, and the third parameter is shaking range, the fourth parameter is whether it is accompanied by the Z axis shaking gridnodetarget-> runaction (shakytiles3d: Create (3.0f, size (), 5, false); break; Case kwavestiles3d: // 3D tile fluctuation effect. The first parameter is duration, the second parameter is grid size, the third parameter is the number of fluctuations, and the fourth parameter is amplitude gridnodetarget-> runaction (wavestiles3d:: Create (3.0f, size (4,120),); break ;}}
View code

In fact, 3D effects are nothing more than making 2D effects more realistic and closer to the real world.

Cocos2d-x Study Notes (12) 3D Effects

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.