Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to make Cocos Studio 2.3.2 make controls in UI interface support running 3D action special effects

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article shows you how to make Cocos Studio 2.3.2 UI interface controls to support running 3D action special effects, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.

Introduction

After class is a little empty, recall the day before yesterday in Studio UI control 3D action problems, or a little worried, after all, 3D advanced action effects is a game development "magic weapon". After carefully studying 3D advanced action effects such as Waves3D, I found an indirect approach as shown in the title.

Implementation process recording

The above picture first, and the following picture shows a screenshot of the startup scene in my teaching game in Cocos Studio 2.3.2. Students can pay attention to the part I marked in the picture.

Obviously, in the figure above, I could easily get the button Button_Start to run the Waves3D action in the original Cocos2d-x 2.x (combined with the earlier CocoStudio 2.4.0.1). However, because the current Waves3D action requires that the operator to run this action must be of type NodeGrid, and the above button inherits from Widget,Widget and inherits from ProtectedNode, the previous code throws an exception when running the corresponding Waves3D action code below.

CCActionInterval* waves1 = CCWaves3D::create (10, CCSizeMake (15jue 10), 18,5); Button_Start- > runAction (CCRepeatForever::create (waves1))

While not reconciled, I analyzed the relevant code in cpp-tests. The main reference file is EffectsAdvancedTest.cpp, and there are a lot of related codes, mainly referring to the following codes:

Auto waves = Waves::create (5, Size (15Power10), 5,20, true, false); auto shaky = Shaky3D::create (5, Size (15d10), 4, false); _ target1- > runAction (RepeatForever::create (waves)); _ target2- > runAction (RepeatForever::create (shaky))

Note: the variable types _ target1 and _ target2 are NodeGrid type pointers.

Obviously, if my Button_Start were a subclass of type NodeGrid, then everything would be OK, but it wasn't.

Next, I analyze the following example.

This example describes the scenario of dynamically adding generic Node to the scene in a Widget control created by 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 (rootSize.width / 2.0f, rootSize.height / 2.0f); widget- > setLocalZOrder (_ layout- > getLocalZOrder () + 1); _ layout- > addChild (widget); Sprite* sprite = Sprite::create ("cocosui/ccicon.png") Widget- > addChild (sprite);}

Next, it occurred to me that today's Studio can easily add Sprite child nodes to Widget controls, as shown in the following figure.

The picture above is very important.

The default anchor for Sprite_1 is (0.5), and so is the anchor for the Button above (0.5). It's just that the coordinates of Sprite_1 are (0c0). Obviously, this is the relative coordinate of his father, and if you look closely (not in the image above), you will certainly notice the coordinates of that Button, that is, relative to the world coordinates of the whole scene.

Solution

According to the comprehensive analysis of the above code, we can add NodeGrid child node to Widget, then add Sprite node to NodeGrid, and adjust the relative coordinate position of NodeGrid under its parent node. Finally, let NodeGrid run special effects like Waves3D.

In my example above, the relevant answer code is as follows:

Button* Button_Start = static_cast (Helper::seekWidgetByName (Panel_Back, "Button_Start")); NodeGrid * _ bgNode = NodeGrid::create (); / / tested, it is not related to the following anchor 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 (10, CCSizeMake (15,10), 18,5); _ bgNode- > runAction (CCRepeatForever::create (waves1))

You see, there is indeed a turn above, but it has achieved the animation effect that we have been longing for for a long time. To sum up, there is one more part that needs to be added: if you use the above scheme, you can only use some temporary placeholder methods at Studio design time, such as a 1-pixel wizard image that first occupies the position of Button.

The above content is how to make Cocos Studio 2.3.2 make UI interface controls to support running 3D action special effects, have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report