Game configuration method and system based on cocos and electronic device
Through the Cocos-based game configuration method, the problem of the complexity of game software development and the difficulty of H5 page technology to meet the high interactive needs is solved, efficient game development and mass production is achieved, cost reduction and system scalability is improved.
Patent Information
- Application Number
- CN202411270937.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-11
- Publication Date
- 2024-12-13
AI Technical Summary
The existing game software is complex to develop, has high modification and maintenance costs, and the existing H5 page technology is difficult to meet the needs of high interaction and batch production.
Using Cocos-based game configuration method, by constraining development templates and specifications, creating interactive SDKs, embed Cocos gameplay information into the H5 page, building a configuration platform for integration, and generating runnable execution files through compilation to realize Cocos games and Communication mechanism between H5 pages.
It reduces development costs, improves development efficiency and system scalability, and can quickly build high-interactive and high-frequency game projects, suitable for industrial batch output.
Smart Images

Figure CN119127293A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of game software development, and in particular to a game configuration method and system, and an electronic device based on Cocos. Background Art
[0002] The development of game software is very complex, including the design of game concepts and mechanisms, characters, stories, levels, etc., and is implemented in programming languages. Due to the complexity of the software, it is difficult and costly to modify, update and maintain.
[0003] Some game products are very popular, which may lead to explosive growth in the number of activities and players' demands for playability and high quality of activities. It has become a relatively difficult problem to rely solely on manpower to support the development of interactive high-quality activities.
[0004] Therefore, the solutions provided by the industry are technical solutions and models for building h5 pages (such as Yiqixiu, etc.), but these are lightweight interactive solutions that tend to be static pages or simple GIF images and simple animations, which are difficult to meet the needs of the current market.
[0005] Others develop highly interactive game products on h5 pages. The solution they adopt is to use cocos to develop games and finally package them into an h5 page. However, this method tends to be customized, and the development and modification costs are high, which is not suitable for industrial mass production.
[0006] Therefore, the industry needs a new solution to deliver a large number of highly interactive scenario-based activity projects with high quality and frequency, while reducing the labor cost of development. Summary of the invention
[0007] To solve the above problems, the present invention provides a game configuration method based on Cocos, comprising:
[0008] S1: Constrain the cocos development template and development specifications;
[0009] S2: Create an interactive SDK: embed the cocos template and information related to the gameplay into the h5 page;
[0010] S3: Build a configuration platform to integrate the game's front-end functions with the h5 page;
[0011] S4: forming the front-end code according to the basic configuration, attributes and links generated by the operation of the configuration platform;
[0012] S5: Compile the front-end code to generate an executable file.
[0013] Furthermore, in step S2, the information related to the gameplay in the cocos game is embedded into the h5 page through the i frame tag, and the i frame tag includes: the component needs to pass in ref, src, wi dth, head, and name attributes.
[0014] Further, step S2 includes:
[0015] S21: cocos generates and exports an html page opened in the h5 page by using cocos creator and basic controls;
[0016] S22: embed any cocos game page into the current h5 page through the i frame tag;
[0017] S23: Establish a communication mechanism between the cocos game and the h5 page through postmessage, and the front-end h5 page monitors and manages the game status through the interactive SDK.
[0018] Furthermore, step S23 establishes a communication mechanism between the cocos game and the h5 page through postmessage, and the front-end h5 page monitors and manages the game status through the interactive SDK, including:
[0019] S231: abstract and encapsulate the atomic API and provide SDK;
[0020] S232: SDK provides monitoring and sending messages, specifically:
[0021] Initialization phase: the h5 page sends a message to notify the cocos game page to initialize the specified resource materials, skins, etc., and initialize the loading of the game;
[0022] Starting stage: the h5 page sends a message to notify the cocos game page to start the game;
[0023] Game ending or game failure stage: the cocos game page sends a message to notify the h5 page of the end, so that the h5 page displays the corresponding status.
[0024] Furthermore, the steps of establishing a communication mechanism between the cocos game and the h5 page through postmessage include:
[0025] Define that the messages sent and received follow a unified message format;
[0026] h5 page sends a message;
[0027] Cocos game receives the message and verifies the source of the message;
[0028] Cocos processes the message and executes the corresponding logic according to the message type and action;
[0029] Cocos returns the current game status to the h5 page.
[0030] Furthermore, the configuration platform basic material center, game materials, and editor in step S3 include:
[0031] The basic material center includes modular login, sharing, and lottery;
[0032] The game materials are the basic game pages developed based on Cocos;
[0033] The editor selects the corresponding materials, combines them into an activity page, and generates the activity and h5 page that are delivered to the client.
[0034] The present application also provides a game configuration system based on Cocos, including a constraint unit, a front-end integration unit, a configuration unit, a code generation unit and a compilation unit, wherein:
[0035] The constraint unit is used to constrain the cocos development template and development specifications;
[0036] The front-end integration unit is used to create an interactive SDK: embed the gameplay information in the cocos game into the h5 page and integrate the cocos development template with the front-end;
[0037] The configuration unit is used to build a configuration platform to integrate the game's front-end functions with the h5 page;
[0038] The code generation unit is used to generate basic configurations, properties and links according to the operations of the configuration platform to form front-end codes;
[0039] The compiling unit is used to compile the front-end code to generate an executable file.
[0040] The present application also provides a computer storage medium, which can store an executable program. When the executable program runs on a computer, the computer executes the Cocos-based game configuration method.
[0041] The present application also provides an electronic device, which includes a processor and a memory, wherein the memory is used to store an executable program, and the processor is used to execute the executable program to implement the Cocos-based game configuration method.
[0042] In order to have a clearer and more comprehensive understanding of the present invention, the specific implementation methods of the present invention are described in detail below in conjunction with the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application, and those skilled in the art can obtain other drawings based on these drawings without creative work.
[0044] Figure 1 This is a flowchart of the game configuration method based on Cocos in this application.
[0045] Figure 2 This is a structural diagram of establishing a cocos development template and embedding it into an h5 page in an embodiment of the present application.
[0046] Figure 3 This is a schematic diagram of embedding the cocos template of an embodiment of the present application and information related to the gameplay into an h5 page.
[0047] Figure 4 This is a structural diagram of an embodiment of the present application that integrates the front-end functions of the game with the h5 page. DETAILED DESCRIPTION
[0048] The technical solutions in the embodiments of the present application will be described clearly and completely below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present application.
[0049] This application highly strips and atomizes the gameplay itself, without adding business logic, so that it can be used as an atomic gameplay point for various activities. That is, by dynamically integrating highly interactive and highly coupled Cocos games with front-end h5 pages, and designing dedicated interactive SDKs and development specifications, Cocos games are made dynamic and interact with h5 pages, so that Cocos games can be modularly embedded in any h5 page, greatly improving development efficiency and system scalability.
[0050] This application can use common marketing materials and game materials on a low-code configuration platform to quickly build a highly interactive marketing campaign page at low cost, which not only greatly reduces the cost of output, but also increases the reuse rate of game materials. At the same time, it can also continuously accumulate materials to help product operations better configure more high-interaction marketing pages.
[0051] Based on this, see Figure 1 , Figure 1This is a flowchart of the game configuration method based on Cocos in this application. The technical solution of this application is:
[0052] S1: Constrain the cocos development template and development specifications;
[0053] S2: Create an interactive SDK: embed the cocos template and information related to the gameplay into the h5 page;
[0054] S3: Build a configuration platform to integrate the game's front-end functions with the h5 page;
[0055] S4: forming the front-end code according to the basic configuration, attributes and links generated by the operation of the configuration platform;
[0056] S5: Compile the front-end code to generate an executable file. The technical solution of the present application is described in detail below in conjunction with various specific or preferred embodiments.
[0057] S1: Constrain the cocos development template and development specifications, and embed the gameplay information in the cocos game into the h5 page;
[0058] See also Figure 2 , the figure is a structural schematic diagram of establishing a cocos development template and embedding it into an h5 page in an embodiment of the present application.
[0059] This step strictly constrains the Cocos development templates and specifications, and combines them with the functions of the h5 page in actual game development. This includes framework version control, modular design such as specifying the interface and interaction method of the module, as well as event handling mechanisms, game logic specifications, etc.
[0060] The template provides common controls for game development, and completes a custom control by extending and using the life cycle, including initializing controls, removing event listeners, etc. The sample code is as follows:
[0061]
[0062] When using it, you only need to add it to the corresponding node to use it. The example is as follows:
[0063]
[0064] In addition, for references to in-game materials, backgrounds, etc., we use a dynamic approach, so that the low-code can dynamically provide the corresponding materials to the game during configuration, initialize them, and notify the h5 page of the dynamic materials for loading and use.
[0065] S2: Create an interactive SDK: embed the cocos template and information related to the gameplay into the h5 page.
[0066] This application embeds information related to the gameplay into the h5 page, without business data, to ensure the flexibility and scalability of the gameplay.
[0067] Use the Cocos engine to package the game project into a web format (usually HTML5) to generate game files that can be run in a browser. These files include HTML, JavaScript, and resource files (such as pictures, audio, etc.).
[0068] In addition, as another preferred method, cross-domain issues need to be considered. If the Cocos game and the h5 page are not in the same domain name, cross-domain issues need to be handled. This can be solved by setting the CORS (cross-origin resource sharing) header or using a proxy server.
[0069] See also Figure 3 , Figure 3 This is a schematic diagram of embedding the cocos template and information related to the gameplay into an h5 page in an embodiment of the present application. As a preferred implementation, the steps include S21-S23:
[0070] S21: cocos generates and exports an html page opened in the h5 page by using cocos creator and basic controls;
[0071] S22: embed any cocos game page into the current h5 page (i.e., h5 activity page) through the i frame tag;
[0072] In the h5 page, by <iframe> The tag embeds the packaged Cocos game. The i frame tag includes: the component needs to pass in the ref, src, width, height, name attributes. The i frame allows an HTML document to be embedded in another HTML document, thereby separating the game from the page. As an example code, it is as follows:
[0073] Figure 4< / iframe>
[0074] S23: Establish a communication mechanism between the cocos game and the h5 page through postmessage, and the front-end h5 page monitors and manages the game status through the interactive SDK.
[0075] PostMessage is a cross-document message delivery mechanism that allows windows from different sources to communicate. In practice, although it is feasible to directly use the postmessage API to call and receive each other, it is troublesome and has security issues (such as encryption, etc.). Therefore, this application makes improvements. That is, by creating an interactive SDK, the postmessage API is encapsulated as a general SDK for use. The method is as follows: Steps S231-S232:
[0076] S231: In order to facilitate the template dynamic capabilities, the most atomic API is abstracted and encapsulated to provide an SDK that is convenient for developers to use.
[0077] The technical solution is: we will provide an I frame component, which needs to pass in attributes such as ref, src, width, height, name, etc. to control the name, address, size, and usage of the iframe, so that we can notify and listen to the corresponding messages within the method specified by the page or the life cycle to perform corresponding operations.
[0078] The following is an example of a react component that uses a custom CustomIframe component and interacts with it through iframeRef. Specifically, it includes the CustomI frame component and the ParentComponent component, where:
[0079] CustomI frame component:
[0080] This component contains an iframe and uses the postMessage method to send messages.
[0081] Listen for messages from the iframe via window.addEventListener and call this.props.onMessage when a message is received
[0082] ParentComponent component:
[0083] Reference the CustomIframe via i frameRef and send the message in componentDidMount.
[0084] Listen for messages from the i frame and output the received information to the console.
[0085] The code example of the above react component is as follows:
[0086]
[0087]
[0088] For the use of Cocos game side, since Cocos itself does not have such capabilities, we will encapsulate a js file, that is, a JavaScript module for cross-document message transmission, which implements the sending and receiving of messages through the postMessage API. All the methods used can be hung on the Windows object. Specifically, they include:
[0089] Global scope:
[0090] Use (function(gl oba l){...})(window); to encapsulate the code in an immediately executed function expression to avoid polluting the global namespace.
[0091] Get script tag attributes:
[0092] Select a specific<scr ipt> Tag and get its data-name and data-origin attributes.
[0093] data-name is used to identify the name of the message, and data-origin is used to specify the target source of the message. The default is '*' (allowing all sources).
[0094] Message sending function:
[0095] The postMessageWrapper(data) function is used to send a message. It constructs an object containing name and data and sends it through gl oba l.postMessage.
[0096] Message receiving function:
[0097] The onMessageWrapper(event) function is used to process the received message. It first checks whether the source of the message matches the targetOr igin, and then calls the global don function (if it exists) to process the message.
[0098] Global method exposure:
[0099] Assign the postMessageWrapper function to gl oba l.demit so that it can be called globally.
[0100] Register a message event listener through gl oba l.addEventListener to receive messages from other windows or i frame.
[0101] S232: SDK provides monitoring and sending messages, specifically:
[0102] Initialization stage: The h5 page can send a message to notify the cocos game page to initialize the specified resource materials, skins, etc., and initialize the loading of the game;
[0103] Starting stage: the h5 page can send a message to notify the cocos game page to start the game;
[0104] Game end or game failure stage: the cocos game page can send a message to notify the h5 page of the end, so that the h5 page displays the corresponding status.
[0105] As a preferred implementation, step S23 establishes a communication mechanism between the cocos game and the h5 page through postmessage, and the steps include:
[0106] Define message formats to ensure that all messages sent and received follow a unified format for easy understanding and parsing;
[0107] Send message: The h5 page sends a message to the embedded Cocos game through the postMessage API, including the message type and action (such as start, pause, resume, etc.).
[0108] Receive messages: Cocos games use window.addEventListener('message',...) to listen to message events and receive messages from h5 pages.
[0109] Verify the source of the message: In Cocos games, verify the event.origin to ensure that the source of the message is credible to prevent potential security risks.
[0110] Processing messages: Based on the type and action of the message, the Cocos game executes the corresponding logic (such as starting, pausing, ending the game, etc.).
[0111] Status request and response: The h5 page can send a status request message. After receiving the request, the Cocos game returns the current game status (such as score, level, etc.).
[0112] Unified message format: Define a unified message format to ensure that messages between H5 pages and Cocos games can be correctly understood and parsed.
[0113] S3: Build a configuration platform to integrate the game's front-end functions with the h5 page.
[0114] See also Figure 4 , This is a schematic diagram of the structure of integrating the front-end functions of the game with the h5 page in the embodiment of the present application. The front-end functions of the game are integrated with the configuration platform described in step S3 of the h5 page, including the front-end functions such as the basic material center, game materials, editors, skins, scenes, etc., wherein:
[0115] The basic material center includes modular login, sharing, and lottery;
[0116] The game materials are the basic game pages developed based on Cocos;
[0117] The editor selects the corresponding materials, combines them into an activity page, and finally generates an activity and h5 page that are delivered to the client.
[0118] S4: forming the front-end code according to the basic configuration, attributes and links generated by the operation of the configuration platform;
[0119] S5: Compile the front-end code to generate an executable file, generate a final external html+js+css folder, and finally publish it to CDN through operation and maintenance deployment, so that it can be released to the outside and the game can be run online.
[0120] Based on the above embodiments, the present application also provides a game configuration system based on Cocos, including a constraint unit, a front-end integration unit, a configuration unit, a code generation unit and a compilation unit, wherein:
[0121] The constraint unit is used to constrain the cocos development template and development specifications;
[0122] The front-end integration unit is used to create an interactive SDK: embed the gameplay information in the cocos game into the h5 page, and integrate the cocos development template with the front-end;
[0123] The configuration unit is used to build a configuration platform to integrate the game's front-end functions with the h5 page;
[0124] The code generation unit is used to generate basic configurations, properties and links according to the operations of the configuration platform to form front-end codes;
[0125] The compiling unit is used to compile the front-end code to generate an executable file.
[0126] The present application also provides a computer storage medium, which can store an executable program. When the executable program runs on a computer, the computer executes the Cocos-based game configuration method described in any of the above embodiments.
[0127] The present application also provides an electronic device, which includes a processor and a memory, wherein the memory is used to store an executable program, and the processor is used to execute the executable program to implement the above-mentioned Cocos-based game configuration method.
[0128] It should be noted that, a person skilled in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing related hardware through a computer program, and the computer program can be stored in a computer-readable storage medium, and the storage medium can include but is not limited to: read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.
[0129] The above description of the disclosed embodiments enables one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A game configuration method based on Cocos, characterized in that: The steps include: S1: Constrain the cocos development template and development specifications; S2: Create an interactive SDK: embed the cocos template and information related to the gameplay into the h5 page; S3: Build a configuration platform to integrate the game's front-end functions with the h5 page; S4: forming the front-end code according to the basic configuration, attributes and links generated by the operation of the configuration platform; S5: Compile the front-end code to generate an executable file.
2. The game configuration method based on Cocos as claimed in claim 1, characterized in that: In step S2, the gameplay information in the cocos game is embedded into the h5 page through the iframe tag. The iframe tag includes: the component needs to pass in ref, src, width, height, and name attributes.
3. The game configuration method based on Cocos as claimed in claim 2, characterized in that: Step S2 includes: S21: cocos generates and exports an html page opened in the h5 page by using cocos creator and basic controls; S22: embed any cocos game page into the current h5 page through the iframe tag; S23: Establish a communication mechanism between the cocos game and the h5 page through postmessage, and the front-end h5 page monitors and manages the game status through the interactive SDK.
4. The game configuration method based on Cocos as claimed in claim 3, characterized in that: Step S23 establishes a communication mechanism between the cocos game and the h5 page through postmessage. The front-end h5 page monitors and manages the game status through the interactive SDK, including: S231: abstract and encapsulate the atomic API and provide SDK; S232: SDK provides monitoring and sending messages, specifically: Initialization phase: the h5 page sends a message to notify the cocos game page to initialize the specified resource materials, skins, etc., and initialize the loading of the game; Starting stage: the h5 page sends a message to notify the cocos game page to start the game; Game ending or game failure stage: the cocos game page sends a message to notify the h5 page of the end, so that the h5 page displays the corresponding status.
5. The game configuration method based on Cocos as claimed in claim 4, characterized in that: The steps to establish the communication mechanism between the cocos game and the h5 page through postmessage include: Define that the messages sent and received follow a unified message format; h5 page sends a message; Cocos game receives the message and verifies the source of the message; Cocos processes the message and executes the corresponding logic according to the message type and action; Cocos returns the current game status to the h5 page.
6. The game configuration method based on Cocos as claimed in claim 1, characterized in that: Step S3: configure the platform basic material center, game materials, and editor, wherein: The basic material center includes modular login, sharing, and lottery; The game materials are the basic game pages developed based on Cocos; The editor selects the corresponding materials, combines them into an activity page, and generates the activity and h5 page that are delivered to the client.
7. A game configuration system based on Cocos, characterized in that: It includes constraint unit, front-end integration unit, configuration unit, code generation unit and compilation unit, among which: The constraint unit is used to constrain the cocos development template and development specifications; The front-end integration unit is used to create an interactive SDK: embed the gameplay information in the cocos game into the h5 page and integrate the cocos development template with the front-end; The configuration unit is used to build a configuration platform to integrate the game's front-end functions with the h5 page; The code generation unit is used to generate basic configurations, properties and links according to the operations of the configuration platform to form front-end codes; The compiling unit is used to compile the front-end code to generate an executable file.
8. A computer storage medium, characterized in that: The computer storage medium may store an executable program. When the executable program runs on a computer, the computer executes any one of the Cocos-based game configuration methods of claims 1-6.
9. An electronic device, characterized in that: The electronic device includes a processor and a memory, the memory is used to store an executable program, and the processor is used to execute the executable program to implement the Cocos-based game configuration method described in claims 1-6.
Citation Information
Cited By
Self-adaptive document encryption method based on text content and medium page number
CN119720258A
Adaptive document encryption method based on text content and media page number
CN119720258B
