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
Table of contents I've been learning React re...
Fault site: Log in to the MySQL server and get th...
Generally, when we use a table, we always give it...
Table of contents 1. How are structures stored in...
(P4) Web standards are composed of a series of sta...
The following demonstration is based on MySQL ver...
On the road to self-learning game development, th...
Table of contents 1. Scenario Description 2. Solu...
Table of contents chmod Example Special attention...
This article tests the environment: CentOS 7 64-b...
Recently, I encountered a problem in the process ...
Today, in the practice of vue3+vite project, when...
When making web pages, you often encounter the pr...
This article is based on the Windows 10 system en...
Main library execution CREATE DATABASE test CHARA...