Basic use of Tui-x and basic use of tui-x

Source: Internet
Author: User
Tags image png

Basic use of Tui-x and basic use of tui-x

This chapter provides a detailed description of the HelloTuiCpp project in the Tui-x3.0 repository. [Because all the controls demonstrated in HelloTuiCpp are limited in length and cannot be described one by one, only two controls can be listed. The subsequent articles will explain how to create other controls in a targeted manner, however, most controls are made in a similar way.]

Preparation:

FlashCS5.5 +, Cocos2dx3.0 official version, Tui-x 3.0, VS 2012 +

1. Create a scenario. Open FlashCS and create a new fla file,Modify the scenario name andSave.

Here we create a main. fla, and then create some folders in the library on the right. Although these folders are virtual, the exported control resource paths will correspond to these folders one by one, we need to create the corresponding directory in the project Resource. For example,


2. Create a main container panel. Ctrl + F8 create a video clip and name it with the prefix panel _. It is recommended that it be related to the scenario, such as panel_main.

Tui-x has naming rules, including fixed sub-prefixes and fixed suffixes. For example, panel _ is a fixed prefix. The naming rules in the control will be detailed in subsequent articles. Click OK. Because panel is a container control, it is placed first.

Set the width and height of the stage. Here we use 800*480 as an example.


3. Create a control.

Create an image control first. Ctrl + F8 create a video clip and change it to img_mainbg. Note that the origin of all controls is in the center, because it must be consistent with the default anchpoint of c2dx. And save it in the main file of the library.

At this time, we need to put an image named img_mainbg.png under Resource/main. Then, return to FlashCS, enter the img_bg, drag the bitmap, and center it relative to the stage, because we will use this image to occupy the position.

Emphasize that the png image you drag into the flash is purely used for space occupation, and the resources used in the game are still the resources corresponding to the Resource. I recommend that you create an irrelevant directory res in the Flash library to exclusively store these png bitmaps.


Next, create a button. Ctrl + F8 create a video clip and change it to btn_ OK. Save it in the main folder of the library. We also need to prepare the corresponding resources to Resouce/main. Here, refer to btn_ OK _normal.png, btn_ OK _select.pngand btn_ OK _disable.png. Here _ normal, _ select, _ disable is the fixed Suffix of Tui-x, which will also be detailed in later chapters.

We entered the btn_ OK's internalization, and then dragged a btn_ OK _normal.png bitmap into the placeholder, and the stage was centered. In this way, the control is ready in our library.


4. Layout

With the control, we can start the layout. First, drag the panel_main in the database to the center of the stage. Note that it is the center of the stage. For example, if the stage is 800*480, it is placed in the place where x = 400, y = 240. The purpose is to facilitate the conversion of c2dx coordinates. And the name of the instance. We recommend that you use the same name as the control, because the tag table exported later will generate the key value based on the Instance name. (Of course, it doesn't matter if you just get started, as long as you don't repeat it)

The panel control is the main container and the receiver of the touch event. Therefore, all controls must be placed in the panel.


Next, we enter the panel_main and drag btn_ OK into it. Random location. Remember, you must have a good instance name. Otherwise, the control cannot be generated.


Next, we can set a namespace according to the project's needs, which can effectively prevent resource rename. Because the buttons in many scenarios are called btn_ OK, the role of the naming control is reflected in this time. It is also easy to set a namespace. You only need to name the frame in the scenario. (Of course, it's okay if you don't set it)


Finally, confirm that all the controls on the stage have the Instance name, and you can start exporting the xml and. h.

5. Export xml and tag tables

The exciting time has arrived. Open TuiEditer_cpp.jsfl in Flash CS (The lua project uses TuiEditer_lua.jsfl), and scroll down to the bottom. There are two paths to be slightly configured. One is the exported xml Path, one is the location where the tag table is exported. Click main. fla to make it active, and then click TuiEditer. jsfl again. If the path is correct, you can click the triangle to run.

At this time, you will find that two files are exported. One is xml and the other is. h.


6. Write and load the code.

The next step is the programmer's work. Create a common project first. Then, create a mainui class and introduce the. h you just generated. The following is a code snippet. For more information about the code, see HelloTuiCpp. cocosBase is used in combination. Here, Tui-x is mainly used to create components based on your xml content after resources are loaded in your scenario. At this time, you can use the provided tag table to directly obtain the corresponding control using getChildByTag and listen to the corresponding events, which is very free and convenient.


Running result:


7. Description

There are two ways to create a Tui-x Control: one is to directly use a scatter image png, and the other is to use plist to package a texture. If you are using a packaging texture, you should note that when using TP to package, you should also package the path of the directory where the png is located. Do not drag the graph into TP directly, you should click Add folder and go to the top layer of the path you want to package. The blue directory indicates the packaging path. Next, load these plist charts into the game before setting the setUseSpriteFrame of TuiManager to true and calling parseScene, the developer has full control over how to manage and how many plist entries. By the way, TuiBase also has a practical function. After setAutoRemoveUnusedSpriteFrame (true) is set, the unused SpriteFrame will be deleted in the scenario analysis structure, to reduce the memory pressure.


CocosWidget official group 261286285 Tui-x official group 347085657

7. Download

Tui-x 2.x: https://github.com/LingJiJian/tui/tree/Tui-x Tui-x 3.x https://github.com/LingJiJian/Tui-x




The basic tutorial of gray pigeon is very detailed.

I don't know my answer. Can I help you with www.myhack58.com/Article/54/93/2009/25190.htm?

What is the basic analysis of x1-x2 + x3 = 0? How? Urgent

The transpose of 1-1 is the column vector.
 

Related Article

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.