In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to operate plist files in Cocos. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
[nagging]
The plist file is a very common configuration file in Cocos. It is an xml file in a specific format.
For example: small images packaged into large texture images, the production of particle effects, frame animation, etc., all use the plist file as a configuration file.
How to create plist files and read data information in plist files.
[plist file]
A property list (Property List) file is a file that stores serialized objects.
The property list file has a file extension of .plist, so it is often referred to as a plist file.
1. The application of plist file in Cocos
(1) configuration information of image texture
Package a number of small texture pictures into a large picture, and generate a plist file. Used to configure information such as the name, size, and location of the rectangular area in the larger image.
You can use the TexturePacker tool to package the textures of multiple small fragments into a large picture.
(2) configuration information of frame animation
The data information of the frame animation is generated as a plist configuration file. Contains information such as the interval between each frame, the number of repetitions of the animation, the required picture for each frame, the name, size, and location of the rectangular area in the larger image.
(3) configuration information of particle special effects.
The data information of the particle effects is generated as a plist configuration file. Contains information about the position of the particle emitter, emitter mode, maximum number of particles, emission angle, emission speed, texture map, and so on.
(4) there are others.
2. Plist file format
The plist file is a property list file, similar to the form of key-value pairs (key-value).
Examples of plist files:
/ / dict name Alice age 20 array 01 2 bool data date 2015-02-16T16:47:11Z number 123456 string hello world!//
The attribute types are:
> Dictionary: dictionary. (the list of sub-attributes is in the form of key-value pairs)
> Array: array. (the list of child attributes is in the form of array values)
> Boolean: logical value. (true / false)
> Number: number.
> String: string.
> Date: date.
> Data: data.
Where the root node can only be a dictionary or an array.
And in the dictionary or array, the values corresponding to the keys can still be the above attribute types.
3. Create / edit plist files
In Mac OS systems, XCode can create and edit plist files directly.
Of course, you can also use plist editing software, or directly use a text editor to write.
In XCode, editing plist files is very convenient.
Where the root node Root can only be of type Dictionary, or Array.
The above plist file data is in the form of the following code:
/ / dict name Alice age 20 array 01 2 bool data date 2015-02-16T16:47:11Z number 123456 string hello world!//
I think everyone should be able to read it.
4. Read plist file
Next, let's talk about how to read the data information from a plist file.
(1) the root node is Dictionary: use FileUtils::getInstance ()-> getValueMapFromFile (); read as a ValueMap.
(2) the root node is Array: use FileUtils::getInstance ()-> getValueVectorFromFile (); read as a ValueVector.
Examples of use:
/ File path std::string path = "/ soft/cocos2d-x-3.4/projects/Demo34/Resources/testPlist.plist"; / / read the plist file / / take the root node as the dictionary Dictionary as an example / / the root node as the dictionary Dictionary, read as a ValueMap ValueMap plist = FileUtils::getInstance ()-> getValueMapFromFile (path) / / if the root node is an array Array, read as a ValueVector / / ValueVector plist = FileUtils::getInstance ()-> getValueVectorFromFile (path); / / get data / / read "string" CCLOG ("string =% s", (plist ["string"] .asString ()) .c_str ()) / read "dict", which is also a dictionary ValueMap ValueMap& dict = plist ["dict"] .asValueMap (); CCLOG ("name =% s", (dict ["name"] .asString ()) .c_str ()); CCLOG ("age =% s", (dict ["age"] .asString ()) .c_str ()) / / read "array", which is an array ValueVector ValueVector& array = plist ["array"] .asValueVector (); for (int I = 0; I < array.size (); iTunes +) {Value& value = array [I]; CCLOG ("% d", value.asInt ()) } / / on how to operate the plist file in Cocos is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.