CocosCreator version: 2.4.2 Practical project application of jszipWhen there are a lot of configurations in the game, the file will become very large, so some games will use zip package compression and decompression For example, in the following game, compress the game configuration config.json into a zip package, decompress it after loading, and use Get his configuration compressed package Change .bin to .zip, decompress it, and get all the json configuration files of the game 6M+ before compression The compressed file is 500KB+, which is about 10 times smaller. Using jszip in cocosFirst, download the jszip library from github https://github.com/Stuk/jszip Put the downloaded jszip.min.js in the project assets/libs, and put jszip.d.ts in libs in the project root directory. (jszip.d.ts is in demo) Compress the game's configuration files, multiple json files, into a zip package, change the suffix zip to bin, and put it under resources/config Load the bin file in the code and parse it to get the game item configuration GameItem.json const {ccclass, property} = cc._decorator; @ccclass export default class Helloworld extends cc.Component { onLoad(){ //Load config.bin cc.resources.load("config/config", (err, assets:any)=>{ //Parsing JSZip.loadAsync(assets._buffer).then((zip)=>{ //Get GameItem.json configuration zip.file("GameItem.json").async("text").then((data)=>{ console.log(data); // Convert string to JSON format let json = JSON.parse(data); console.log(json["1"].name); }) }); }) } } Loading and parsing successfully, output The above is the details of how to use JSZip compression in CocosCreator. For more information about CocosCreator JSZip compression, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
<<: Use of environment variables in Docker and solutions to common problems
>>: MySQL Oracle and SQL Server paging query example analysis
Preface This tutorial installs the latest version...
1. Introduction MySQL comes with a replication so...
mycli MyCLI is a command line interface for MySQL...
There is often a lack of understanding of multi-c...
The first line of a Docker image starts with an i...
TRUNCATE TABLE Deletes all rows in a table withou...
Preface Under the influence of some CSS interacti...
The W3C standardization process is divided into 7...
When we open the source code of a regular website...
Table of contents Parent component communicates w...
Effect demo.html <html> <head> <me...
This article shares the specific code of JavaScri...
This article shares the specific code for the WeC...
Copy code The code is as follows: <div style=&...
The detailed process of installing python3.7.0 on...