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

How to configure NAS on Windows Server 2019

Preface This tutorial installs the latest version...

Analyze MySQL replication and tuning principles and methods

1. Introduction MySQL comes with a replication so...

Mycli is a must-have tool for MySQL command line enthusiasts

mycli MyCLI is a command line interface for MySQL...

MySQL independent index and joint index selection

There is often a lack of understanding of multi-c...

Docker uses busybox to create a base image

The first line of a Docker image starts with an i...

Explanation of Truncate Table usage

TRUNCATE TABLE Deletes all rows in a table withou...

Specific use of stacking context in CSS

Preface Under the influence of some CSS interacti...

W3C Tutorial (2): W3C Programs

The W3C standardization process is divided into 7...

HTML version declaration DOCTYPE tag

When we open the source code of a regular website...

Detailed explanation of component communication in react

Table of contents Parent component communicates w...

HTML+VUE paging to achieve cool IoT large screen function

Effect demo.html <html> <head> <me...

JavaScript to implement mobile signature function

This article shares the specific code of JavaScri...

WeChat applet implements calculator function

This article shares the specific code for the WeC...

Python 3.7 installation tutorial for MacBook

The detailed process of installing python3.7.0 on...