Game resource integration method and device based on cocos2dx-Lua
Through the game resource integration method based on cocos2dx-Lua, the scripts and resources of sub-products are decoupled, the public resources and framework code are eliminated, and the sub-package folder is switched to the sub-package folder when the lua code is loaded, the problem of waste of traffic during resource duplication and update in the existing technology is solved, and the separate management of code and resources and the saving of traffic is achieved.
Patent Information
- Application Number
- CN202111572326.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-21
- Publication Date
- 2025-05-23
- Estimated Expiration
- 2041-12-21
AI Technical Summary
In the prior art, game resource integration solutions require the design of sub-product code and resources during the planning stage, resulting in duplication and inability to reuse resources, and waste of traffic during updates.
Through the game resource integration method based on cocos2dx-Lua, the scripts and resources of the sub-products are obtained for decoupling, the public resource and framework code are eliminated, the processed data packets are obtained, and when the lua code is loaded, the code cache of the parent package working directory is cleared and the working directory of the sub-package folder is switched to the sub-package folder.
It realizes that single-item games become subpackages through fine-tuning, and the code and resources are managed separately, saving download traffic and avoiding waste of traffic during resource duplication and updates.
Smart Images

Figure CN114392558B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of games, and in particular to a method and device for integrating game resources based on cocos2dx-Lua. Background Art
[0002] When the number of matrix products reaches a certain level, resources need to be integrated. The existing technology usually adopts the game lobby approach, and the main implementation solution is to download the code and resources to the local computer together, and dynamically load the sub-games through hot updates. However, the disadvantage of this solution is that the sub-products that meet the framework must be designed at the planning stage, and the resources and codes are downloaded at the same time, which wastes traffic when updating. In addition, there are many duplicate resources in the sub-products, and the code resources of the parent product cannot be reused. Summary of the invention
[0003] 1. Technical issues to be resolved
[0004] In order to solve the above problems in the prior art, the present invention provides a game resource integration method and device based on cocos2dx-Lua, which can realize that a single game that has been completed can be used as a sub-package with only minor adjustments, and the code and resources are managed separately, saving download traffic.
[0005] (II) Technical solution
[0006] In order to achieve the above object, a technical solution adopted by the present invention is:
[0007] The game resource integration method based on cocos2dx-Lua includes the following steps:
[0008] S1. Obtain the scripts and resources of the sub-products for decoupling, and remove the common resources and framework codes to obtain the processed data package;
[0009] S2, determining whether a sub-package folder identical to the data package already exists in the local parent package working directory, if not, downloading the data package;
[0010] When S3 and Lua code are loaded, clear the code cache in the working directory of the parent package, switch to the working directory of the child package folder, put the working directory of the parent package behind, and enter the child package.
[0011] In order to achieve the above object, another technical solution adopted by the present invention is:
[0012] The game resource integration device based on cocos2dx-Lua includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the following steps are implemented:
[0013] S1. Obtain the scripts and resources of the sub-products for decoupling, and remove the common resources and framework codes to obtain the processed data package;
[0014] S2, determining whether a sub-package folder identical to the data package already exists in the local parent package working directory, if not, downloading the data package;
[0015] When S3 and Lua code are loaded, clear the code cache in the working directory of the parent package, switch to the working directory of the child package folder, put the working directory of the parent package behind, and enter the child package.
[0016] (III) Beneficial effects
[0017] The beneficial effects of the present invention are as follows: by obtaining the scripts and resources of the sub-product for decoupling, and removing the public resources and framework codes, a processed data packet is obtained; it is determined whether a sub-package folder identical to the data packet already exists in the local parent package working directory, and if not, the data packet is downloaded; when the lua code is loaded, the code cache in the parent package working directory is cleared, the working directory of the sub-package folder is switched to, and the parent package working directory is placed at the back before entering the sub-package, so that a completed single-product game can be used as a sub-package with only minor adjustments, and the code scripts and resources are managed separately, saving download traffic. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 This is a flow chart of a method for integrating game resources based on cocos2dx-Lua according to an embodiment of the present invention;
[0019] Figure 2 Schematic diagram of the overall structure of a game resource integration device based on cocos2dx-Lua according to an embodiment of the present invention.
[0020] [Description of Reference Numerals]
[0021] 1: Game resource integration device based on cocos2dx-Lua;
[0022] 2: Memory;
[0023] 3: Processor. DETAILED DESCRIPTION
[0024] In order to better explain the present invention and facilitate understanding, the present invention is described in detail below through specific implementation modes in conjunction with the accompanying drawings.
[0025] Embodiment 1
[0026] Please refer to Figure 1 , the game resource integration method based on cocos2dx-Lua includes the following steps:
[0027] S1. Obtain the scripts and resources of the sub-products for decoupling, and remove the common resources and framework codes to obtain the processed data package;
[0028] Step S1 is specifically as follows:
[0029] The script res and resource src of the sub-product are obtained to decouple the framework code and the logic code, and the public resources under the script res and the framework code under the resource src are removed through the batch script to obtain the processed data package.
[0030] The batch processing script removes the common resources under the script res and the framework code under the resource src, and the processed data packet is specifically:
[0031] The internationalized voices and pictures under the script res are classified by language through a batch processing script to obtain N language compression packages after processing, and other resources and codes are packaged to obtain a basic compression package.
[0032] Specifically, the language compressed package and the basic compressed package are preferably in zip format, so as to save download traffic and only download the specified language package according to the mobile phone language.
[0033] S2, determining whether a sub-package folder identical to the data package already exists in the local parent package working directory, if not, downloading the data package;
[0034] Specifically, if a sub-package folder identical to the data packet already exists, determining whether the sub-package folder is the latest one, and if not, updating it;
[0035] When S3 and Lua code are loaded, clear the code cache in the working directory of the parent package, switch to the working directory of the child package folder, put the working directory of the parent package behind, and enter the child package.
[0036] Step S3 is specifically as follows:
[0037] S31. When the lua code is loaded, obtain the code cache locations package.preload and package.loaded in the working directory of the parent package, and clear the cache;
[0038] S32. Switch to the working directory of the sub-package folder, put the parent package working directory behind, and enter the sub-package.
[0039] Specifically, by clearing the code cache in the parent package working directory, it is possible to prevent the sub-package code from not being loaded, and ultimately form a sub-product collection to better achieve traffic distribution;
[0040] It also includes steps to set the code cache that needs to be ignored. There are some codes that you hope to continue to use in sub-packages (such as general loading pages, general statistical tool classes, and code frameworks). You can provide the product with an interface to set the code that you want to ignore cache clearing, and support batch retention by code full name, code suffix, and code prefix.
[0041] Embodiment 2
[0042] Please refer to Figure 2 A game resource integration device 1 based on cocos2dx-Lua includes a memory 2, a processor 3, and a computer program stored in the memory 2 and executable on the processor 3. When the processor 3 executes the program, each step in the first embodiment is implemented.
[0043] The above descriptions are merely embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent transformations made using the contents of the present invention's specification and drawings, or directly or indirectly applied in related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. Game resource integration method based on cocos2dx-Lua, It is characterized in that Includes steps: S1. Obtain the scripts and resources of the sub-products for decoupling, and remove the common resources and framework codes to obtain the processed data package; S2, determining whether a sub-package folder identical to the data package already exists in the local parent package working directory, if not, downloading the data package; S3. When the lua code is loaded, clear the code cache in the working directory of the parent package, switch to the working directory of the sub-package folder, put the working directory of the parent package behind, and enter the sub-package; Step S1 is specifically as follows: Get the resource res and script src of the sub-product to decouple the framework code and the logic code, and remove the public resources under the resource res and the framework code under the script src through the batch processing script to obtain the processed data package; The batch processing script removes the common resources under the resource res and the framework code under the script src, and the processed data packet is specifically: The internationalized voices and images under the resource res are classified by language through a batch processing script to obtain N language compression packages after processing, and other resources and codes are packaged to obtain a basic compression package.
2. The game resource integration method based on cocos2dx-Lua according to claim 1, It is characterized in that Step S3 is specifically as follows: S31. When the lua code is loaded, obtain the code cache locations package.preload and package.loaded in the working directory of the parent package, and clear the cache; S32. Switch to the working directory of the sub-package folder, put the parent package working directory behind, and enter the sub-package.
3. A game resource integration device based on cocos2dx-Lua, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, It is characterized in that When the processor executes the program, the following steps are implemented: S1. Obtain the scripts and resources of the sub-products for decoupling, and remove the common resources and framework codes to obtain the processed data package; S2, determining whether a sub-package folder identical to the data package already exists in the local parent package working directory, if not, downloading the data package; S3. When the lua code is loaded, clear the code cache in the working directory of the parent package, switch to the working directory of the sub-package folder, put the working directory of the parent package behind, and enter the sub-package; Step S1 is specifically as follows: Get the resource res and script src of the sub-product to decouple the framework code and the logic code, and remove the public resources under the resource res and the framework code under the script src through the batch processing script to obtain the processed data package; The batch script removes the common resources under the resource res and the framework code under the script src, and the processed data packet is specifically: The internationalized voices and images under the resource res are classified by language through a batch processing script to obtain N language compression packages after processing, and other resources and codes are packaged to obtain a basic compression package.
4. The game resource integration device based on cocos2dx-Lua according to claim 3, It is characterized in that Step S3 is specifically as follows: S31. When the lua code is loaded, obtain the code cache locations package.preload and package.loaded in the working directory of the parent package, and clear the cache; S32. Switch to the working directory of the sub-package folder, put the parent package working directory behind, and enter the sub-package.