Introduction
Under the Class A little empty, recalled the day before yesterday in the studio UI control 3D action problem, or a little worry, after all, 3D advanced action Special effect is a game development "magic weapon." After careful study of WAVES3D and other high-level action effects, I found an indirect approach as shown in the title of this article. Interested friends can refer to.
Implementing Process Logging
First of all, given in my teaching game in the game to start the scene in Cocos Studio 2.3.2, students can notice the part I marked in the picture.
650) this.width=650; "title=" capture. JPG "src=" http://s1.51cto.com/wyfs02/M00/76/6B/wKiom1ZS3AmSoTeXAAIVeBRu8Ak752.jpg "alt=" Wkiom1zs3amsotexaaivebru8ak752.jpg "/>
Obviously, in the original Cocos2d-x 2.x (combined with the early Cocostudio 2.4.0.1) environment, I was able to easily let the button Button_start run Waves3d action. However, because the current WAVES3D action requires that the action be run by the Nodegrid type, and the button above inherits from Widget,widget and inherits from Protectednode, So the previous code throws an exception when it runs to the appropriate run Waves3d action code below.
ccactioninterval* waves1 = ccwaves3d::create (Ccsizemake (15,10), 18, 5); Button_start->runaction (Ccrepeatforever::create (waves1));
In the not reconciled, I also analyzed the relevant code in cpp-tests. The main reference file is EffectsAdvancedTest.cpp, the relevant code is also a lot, mainly refer to the following code:
Auto waves = waves::create (5, Size (15,10), 5, +, True, false); Auto shaky = shaky3d::create (5, Size (15,10), 4, false); _target1->runaction (Repeatforever::create (waves)); _target2->runaction (Repeatforever::create (shaky));
Note: Both the variable types _target1 and _target2 are Nodegrid type pointers.
Obviously, if my button_start is a Nodegrid type subclass, then everything is OK, but it's not.
Next, I analyze the example.
650) this.width=650; "title=" capture. JPG "src=" http://s2.51cto.com/wyfs02/M01/76/6B/wKiom1ZS3tnT2mgLAAFZyqbAfgE466.jpg "alt=" Wkiom1zs3tnt2mglaafzyqbafge466.jpg "/>
This example describes a scenario that dynamically adds a generic node to a scene in a widget control created in studio. The key code is as follows:
void Uiwidgetaddnodetest_editor::configureguiscene () {uiscene_editor::configureguiscene (); Size rootsize = _layout->getcontentsize (); Create the UI widget widget* widget = Widget::create (); Widget->setposition (VEC2 (rootsize.width/2.0f, rootsize.height/2.0f)); Widget->setlocalzorder (_layout->getlocalzorder () + 1); _layout->addchild (widgets); sprite* Sprite = sprite::create ("Cocosui/ccicon.png"); Widget->addchild (sprite);}
Everyone pay attention to the last sentence!!!
Next, I think it's easy to add sprite sub-nodes to widget controls in today's studio, as shown in.
650) this.width=650; "title=" capture. JPG "src=" http://s2.51cto.com/wyfs02/M01/76/6A/wKioL1ZS4DeRkV5xAAKQo93_oQs548.jpg "alt=" wkiol1zs4derkv5xaakqo93_ Oqs548.jpg "/>
The picture above is of paramount importance.
The default anchor point for the sprite_1 is (0.5,0.5), and the anchor of the button above is also (0.5,0.5). Just the coordinates of the sprite_1 are (0,0). Obviously, this is relative to the parent's relative coordinates, and if you look closely (none), you will of course notice the coordinate of the button, which is the world coordinate relative to the entire scene.
Solution Solutions
Based on a comprehensive analysis of the above code, we can add a Nodegrid node to the widget, then add a sprite node to the Nodegrid and adjust the relative coordinate position of the Nodegrid under its parent node. Finally, let Nodegrid run waves3d this special effect action.
In my above example, the relevant answer code is as follows:
button* Button_start = static_cast<button*> (Helper::seekwidgetbyname (Panel_back, "Button_Start")); Nodegrid *_bgnode = Nodegrid::create (); After testing, there is no relationship with the following anchor point coordinates//_bgnode->setanchorpoint (VEC2 (0.5, 0.5)); Button_start->addchild (_bgnode); Auto BG = sprite::create ("Images/backbtnnormal.png"); _bgnode->addchild (BG); _bgnode->setposition (VEC2 (Button_start->getboundingbox (). SIZE.WIDTH/2, Button_start->getboundingbox (). SIZE.HEIGHT/2)); actioninterval* waves1 = waves3d::create (Ccsizemake (15, 10), 18, 5); _bgnode->runaction (Ccrepeatforever::create (waves1));
Summary and supplement
You see, it did turn a corner, but after all, it was the animated effect that we had long been longing for. In summary, there is another part that needs to be added: Using the above scenario, only a few temporary placeholder methods can be used at Studio design time, such as a 1*1-pixel sprite image that occupies the button position first. I am afraid the students are not difficult to understand, here will not repeat.
This article is from the "Green Peak" blog, please make sure to keep this source http://zhuxianzhong.blog.51cto.com/157061/1716084
Allow Cocos Studio 2.3.2 to create a control in the UI interface that supports the indirect way to run 3d action effects