How to use JSZip compression in CocosCreator

How to use JSZip compression in CocosCreator

CocosCreator version: 2.4.2

Practical project application of jszip

When 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 cocos

First, 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:
  • Unity3D realizes camera lens movement and limits the angle
  • Detailed explanation of how to use several timers in CocosCreator
  • CocosCreator learning modular script
  • How to use physics engine joints in CocosCreator
  • CocosCreator Getting Started Tutorial: Making Your First Game with TS
  • Interpretation of CocosCreator source code: engine startup and main loop
  • CocosCreator general framework design resource management
  • How to make a List in CocosCreator
  • How to use http and WebSocket in CocosCreator
  • Analysis of CocosCreator's new resource management system
  • How to use cc.follow for camera tracking in CocosCreator

<<:  Use of environment variables in Docker and solutions to common problems

>>:  MySQL Oracle and SQL Server paging query example analysis

Recommend

Solution to MySQL server login error ERROR 1820 (HY000)

Fault site: Log in to the MySQL server and get th...

HTML table border control implementation code

Generally, when we use a table, we always give it...

Detailed explanation of Linux kernel macro Container_Of

Table of contents 1. How are structures stored in...

Writing High-Quality Code Web Front-End Development Practice Book Excerpts

(P4) Web standards are composed of a series of sta...

Implementation of MySQL select in subquery optimization

The following demonstration is based on MySQL ver...

Detailed explanation on how to deploy H5 games to nginx server

On the road to self-learning game development, th...

A brief discussion on the solution to excessive data in ElementUI el-select

Table of contents 1. Scenario Description 2. Solu...

Install and configure MySQL 5.7 under CentOS 7

This article tests the environment: CentOS 7 64-b...

Detailed explanation of important cascading concepts in CSS

Recently, I encountered a problem in the process ...

Detailed graphic explanation of how to use svg in vue3+vite project

Today, in the practice of vue3+vite project, when...

How to set the width and height of html table cells

When making web pages, you often encounter the pr...

Example of using setInterval function in React

This article is based on the Windows 10 system en...