Graph resource rendering method in game engine

By detecting and parsing the type of graphics resource files, dynamically creating canvases and generating animations, the problem of game engines being unable to render animations such as APNGs is solved, achieving efficient rendering and smooth animation effects, and improving the flexibility of game resources and user experience.

CN121120872APending Publication Date: 2025-12-12HUNAN HAPPLY SUNSHINE INTERACTIVE ENTERTAINMENT MEDIA CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511199326.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-08-25
Publication Date
2025-12-12

AI Technical Summary

Technical Problem

Existing game engines cannot effectively render animation formats such as APNG, resulting in inflexible resource usage, high memory consumption, poor animation effects, and difficulty in aligning with game scenes.

Method used

By detecting the type of graphics resource files, parsing frame image data and attribute information, dynamically creating canvases and generating animations, and converting them into texture data that the game engine can recognize for rendering.

Benefits of technology

It enables efficient rendering of APNG animations in game engines, improves resource loading efficiency and animation quality, and enhances user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121120872A_ABST
    Figure CN121120872A_ABST
Patent Text Reader

Abstract

The invention discloses a graphic resource rendering method in a game engine. The method comprises the following steps: acquiring a graphic resource file corresponding to a target game node in a game engine, and detecting the type of the graphic resource file; under the condition that the type of the graphic resource file is a preset animation format, analyzing frame image data and graphic attribute information in the graphic resource file; and creating a target canvas in the target game node, generating a target animation in the target canvas based on the frame image data and the graphic attribute information, and rendering the target animation to the target game node. The technical problem that in a related scheme, a game engine can only render a static image and cannot normally render animations in formats such as APNG is solved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of computer graphics processing, in particular to a graphics resource rendering method in a game engine. BACKGROUND

[0002] In the current digital entertainment and Internet industry, animation and special effects have become an important means to improve user experience, especially in the fields of games and online interactive entertainment. APNG (Animated Portable Network Graphics) as an extended PNG (Portable Network Graphics) format supporting transparency and animation, is widely welcomed for its balance between quality and resource occupation. However, existing game development frameworks and engines, such as Cocos, Unity, etc., often focus on traditional static image rendering and more complex 3D model processing, and do not fully support APNG animation. Currently, when loading and displaying APNG animation, there are mainly the following problems: 1) the existing game engine can only render ordinary PNG or JPG (Joint Photographic Experts Group) pictures by default, and for APNG animation files, only the first frame or the last frame can be displayed, which cannot fully display the animation effect, which not only limits the flexibility of resource use, but also increases the complexity of integrating APNG animation into the game; 2) the accurate alignment of APNG animation with other elements in the game scene, especially the sub-pixel level alignment, is a technical difficulty, which directly affects the visual effect of animation resources in the game, including the smoothness of the animation and the integration with the interface; 3) frequent playback of APNG animation may cause high memory occupation, which in turn affects the overall performance of the game, and how to optimize memory usage while maintaining animation quality and avoiding resource redundancy is an important issue to improve game running efficiency.

[0003] At present, no effective solution has been proposed to solve the above problems. SUMMARY

[0004] The embodiments of the present application provide a graphics resource rendering method in a game engine, which at least solves the technical problem that the game engine can only render static images and cannot normally render APNG format animation in related solutions.

[0005] According to an aspect of the embodiments of the present application, a method for rendering a graphic resource in a game engine is provided, including: obtaining a graphic resource file corresponding to a target game node in the game engine, and detecting a type of the graphic resource file; in a case where the type of the graphic resource file is a preset animation format, parsing frame image data and graphic attribute information in the graphic resource file; creating a target canvas in the target game node, generating a target animation in the target canvas based on the frame image data and the graphic attribute information, and rendering the target animation to the target game node.

[0006] Optionally, the detecting of the type of the graphic resource file includes: detecting whether a head signature of the graphic resource file matches a preset animation format signature; in a case where the head signature of the graphic resource file matches the animation format signature, determining that the type of the graphic resource file is the preset animation format; and in a case where the head signature of the graphic resource file does not match the animation format signature, determining that the type of the graphic resource file is a static image.

[0007] Optionally, the graphic attribute information includes frame image attribute information, frame control attribute information and animation attribute information, and the parsing of the frame image data and the graphic attribute information in the graphic resource file includes: determining the frame image attribute information from an image head data block of the graphic resource file, and determining the frame control attribute information from a frame control block of the graphic resource file, storing the frame image attribute information and the frame control attribute information to a frame object, wherein the frame image attribute information at least includes frame image size, and the frame control attribute information at least includes display time, display position and display size of the frame image; determining the animation attribute information from an animation control block in the graphic resource file, and storing the animation attribute information to an animation object, wherein the animation attribute information at least includes animation cycle number and total frame number of the animation; and determining frame image data from a frame data block or an image data block in the graphic resource file, and encapsulating each frame image data as a static image based on a binary large object.

[0008] Optionally, the creating of the target canvas in the target game node includes: obtaining game world coordinates corresponding to the target game node and corresponding boundary box size information, and obtaining a device pixel ratio of a target device used for displaying a game picture and display interface size information; determining position information of the target canvas in a display interface according to the game world coordinates and the display interface size information; determining a first ratio between the boundary box size information and the display interface size information, and determining a second ratio between resolution size of the target canvas and the device pixel ratio of the target device, and determining size information of the target canvas based on the first ratio and the second ratio; and configuring the target canvas in the target game node based on the position information and the size information of the target canvas.

[0009] Optionally, the generating the target animation in the target canvas based on the frame image data and the graphic attribute information, and rendering the target animation to the target game node comprises: loading a static image corresponding to each frame of image data into the target canvas; configuring the static image corresponding to each frame of image data based on a frame object to obtain a plurality of frames of animation pictures; configuring the plurality of frames of animation pictures based on an animation object to obtain the target animation; converting the target animation into texture data recognizable by the game engine; and applying the texture data to a display component corresponding to the target game node to complete animation rendering of the target game node.

[0010] Optionally, before detecting the type of the graphic resource file, the method further comprises: detecting validity of the target game node; in the case that the target game node is valid, continuing to detect the type of the graphic resource file; in the case that the target game node is invalid, terminating the subsequent process, and generating a node exception prompt information.

[0011] Optionally, before parsing the frame image data and the graphic attribute information in the graphic resource file, the method further comprises: detecting whether the frame image data and the graphic attribute information corresponding to the graphic resource file exist in the cache database, if yes, directly calling the frame image data and the graphic attribute information, and if not, parsing the frame image data and the graphic attribute information in the graphic resource file; and after parsing the frame image data and the graphic attribute information in the graphic resource file, the method further comprises: storing the frame image data and the graphic attribute information into the cache database.

[0012] Optionally, the method further comprises: in the case that the type of the graphic resource file is a static image, converting the static image into texture data recognizable by the game engine; and applying the texture data to a display component corresponding to the target game node to complete rendering of the target game node.

[0013] According to another aspect of the embodiments of the present application, a graphic resource rendering device in a game engine is further provided, comprising: a detection module configured to acquire a graphic resource file corresponding to a target game node in the game engine, and detect a type of the graphic resource file; an analysis module configured to, in the case that the type of the graphic resource file is a preset animation format, analyze frame image data and graphic attribute information in the graphic resource file; and a rendering module configured to create a target canvas in the target game node, generate a target animation in the target canvas based on the frame image data and the graphic attribute information, and render the target animation to the target game node.

[0014] According to another aspect of the embodiments of the present application, an electronic device is further provided, which comprises a memory and a processor, wherein the memory stores a computer program, and the processor is configured to execute the game engine graphic resource rendering method described above by using the computer program.

[0015] In the embodiment of the present application, by detecting the file type in the initial stage of loading the graphic resource, the animation format file is distinguished from the static image, and corresponding processing strategies can be adopted according to different formats, which is the basis for ensuring the correctness of the subsequent animation playing and static image rendering process; for the animation format file, by extracting the corresponding frame image data and graphic attribute information, the complex animation file can be converted into a series of frame data and metadata that are easy to process, and then the playing order, delay time and cycle number of each frame are accurately controlled, so that more realistic and smooth animation effect is realized; then, a canvas is dynamically created for the corresponding target game node, and an animation is generated in the canvas based on the parsed frame image data and graphic attribute information, and the animation is converted into texture data recognizable by the game engine, and the texture data is applied to the display component corresponding to the game node, so that the animation rendering of the game node is completed. The technical problem that the game engine in the related scheme can only render static images and cannot normally render APNG and other format animations is effectively solved. BRIEF DESCRIPTION OF DRAWINGS

[0016] The accompanying drawings, which are included to provide a further understanding of the present application, constitute a part of the specification and illustrate the illustrative embodiments of the present application and together with the description serve to explain the present application. In the drawings:

[0017] Figure 1 is a flow diagram of an optional graphic resource rendering method in a game engine according to an embodiment of the present application;

[0018] Figure 2 is a structural diagram of an optional graphic resource rendering device in a game engine according to an embodiment of the present application;

[0019] Figure 3 is a structural diagram of an optional electronic device according to an embodiment of the present application. DETAILED DESCRIPTION

[0020] In order to enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, but not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor should fall within the scope of protection of the present application.

[0021] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the drawings are used to distinguish similar objects, and do not necessarily have to describe a specific order or sequence. It should be understood that the data thus used can be interchanged under appropriate circumstances, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion, for example, a process, method, system, product or device that includes a series of steps or units does not have to be limited to those steps or units clearly listed, but can include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0022] Embodiment 1

[0023] According to an embodiment of the present application, a method for rendering a graphic resource in a game engine is provided. It should be noted that the steps shown in the flowchart of the drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described herein can be executed in an order different from that shown herein.

[0024] Figure 1 is a flowchart of a method for rendering a graphic resource in a game engine according to an embodiment of the present application, as shown in Figure 1 , the method comprises the following steps:

[0025] Step S102, obtaining a graphic resource file corresponding to a target game node in the game engine, and detecting the type of the graphic resource file;

[0026] Step S104, in the case where the type of the graphic resource file is a preset animation format, parsing frame image data and graphic attribute information in the graphic resource file;

[0027] Step S106, creating a target canvas in the target game node, generating a target animation in the target canvas based on the frame image data and the graphic attribute information, and rendering the target animation to the target game node.

[0028] Wherein, the preset animation format can be APNG, GIF (Graphics Interchange Format), MNG (Multiple-image Network Graphics) and the like.

[0029] The steps of the method for rendering a graphic resource in a game engine will be explained in detail in combination with the specific implementation process.

[0030] Firstly, a graphic resource file corresponding to a target game node in a game engine needs to be acquired, and the type of the graphic resource file is detected.

[0031] The game node is a basic unit representing a visual UI element or a game object in the game engine, which can carry multiple sub-components (such as Sprite, Transform, etc.), and can be nested in other nodes to form a complex hierarchical structure. In the embodiments of the present application, the node can be an avatar frame in a game interface, which can load a static image or a dynamic animation according to different situations.

[0032] When the system receives a request to render a graphic resource of a specific game node (such as a player avatar, a UI element or a background picture), the identifier in the request, such as the file name, the URL (Uniform Resource Locator, Uniform Resource Locator) or the resource ID, etc. can be parsed, and the graphic resource file stored in the local file system, the remote server or the game resource package can be located according to the identifier.

[0033] As an optional implementation, when the type of the graphic resource file is detected, the following method can be used: detecting whether the header signature of the graphic resource file matches the preset animation format signature; in the case that the header signature of the graphic resource file matches the animation format signature, determining that the type of the graphic resource file is the preset animation format; in the case that the header signature of the graphic resource file does not match the animation format signature, determining that the type of the graphic resource file is a static image.

[0034] It can be understood that the header signature of the file is the key to determine its format, therefore, when the type of the graphic resource file is detected, the header signature of the file can be read first, for example, the standard header signature of the APNG animation should be "0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a", the system compares the first 8 bytes of the file with the standard APNG signature to determine the file format. Specifically, the readAsArrayBuffer method of the FileReader API can be used to read the file data, and the Uint8Array can be used to check whether the first 8 bytes match the APNG signature, if the header signature matches the APNG signature, the system determines that the file is in the APNG format, and prepares to enter the parsing and playing process of the APNG animation, if the header signature does not match, it is determined that the file is a static image, and the loading and rendering process of the static image is directly entered.

[0035] In case that the type of the graphic resource file is detected as the preset animation format, frame image data and graphic attribute information in the graphic resource file need to be further parsed, and the graphic attribute information usually includes frame image attribute information, frame control attribute information and animation attribute information.

[0036] As an optional implementation, in parsing the frame image data and the graphic attribute information in the graphic resource file, frame image attribute information can be determined from an image header data block of the graphic resource file, and frame control attribute information can be determined from a frame control block of the graphic resource file, and the frame image attribute information and the frame control attribute information are stored to a frame object, wherein the frame image attribute information at least includes frame image size, and the frame control attribute information at least includes display time, display position and display size of the frame image; then, animation attribute information can be determined from an animation control block in the graphic resource file, and the animation attribute information is stored to an animation object, wherein the animation attribute information at least includes animation cycle number and total frame number; and frame image data can be determined from a frame data block or an image data block in the graphic resource file, and each frame image data is encapsulated as a static image based on a binary large object.

[0037] Taking the type of the graphic resource file as APNG as an example, first, an IHDR (Image Header) block is read to obtain frame image attribute information such as width and height of the image; then, an fcTL (Frame Control) block is read to extract frame control attribute information such as display time, display position and display size of each frame; then, an acTL (Animation Control) block is parsed to determine animation attribute information such as animation cycle number and total frame number; finally, an fdAT (Frame Data) block or an IDAT (Image Data) block is read to obtain frame image data. After the related data is parsed, the extracted frame image attribute information and the frame control attribute information can be stored to a Frame object, the animation attribute information can be stored to an APNG object, and each frame image data can be encapsulated as an independent PNG image based on a Blob (Binary Large Object) that can be processed by a browser and WebGL, and the specific format is: PNG header + global data + current frame data + PNG tail.

[0038] It should be noted that once it is detected that a key data block such as acTL, fcTL, fdAT or IDAT is missing, the APNG file should be immediately stopped from being parsed to avoid error rendering or program exception caused by incomplete data.

[0039] To improve graphics processing efficiency, after parsing the frame image data and graphics attribute information in the graphics resource file, this data can be stored in a cache database. In the next graphics resource rendering task, before parsing the frame image data and graphics attribute information in the graphics resource file, the cache database can be checked to see if the corresponding frame image data and graphics attributes exist. If they do, the data can be directly retrieved; otherwise, the process continues parsing the frame image data and graphics attribute information in the graphics resource file.

[0040] After parsing and saving the relevant data, a target canvas can be created in the target game node. Based on the frame image data and graphic attribute information, a target animation can be generated in the target canvas and rendered to the target game node.

[0041] As an optional implementation, a target canvas can be created in the target game node as follows: obtain the game world coordinates and corresponding bounding box size information corresponding to the target game node, and obtain the device pixel ratio and display interface size information of the target device used to display the game screen; determine the position information of the target canvas in the display interface based on the game world coordinates and display interface size information; determine a first ratio between the bounding box size information and the display interface size information, and determine a second ratio between the resolution size of the target canvas and the device pixel ratio of the target device; determine the size information of the target canvas based on the first ratio and the second ratio; configure the target canvas in the target game node based on the position information and size information of the target canvas.

[0042] Specifically, the position and size information of the target canvas in the display interface can be determined based on the following formula:

[0043]

[0044]

[0045] In the formula, X ′ and Y ′ X and Y represent the percentage position of the target canvas in the display interface, respectively; X and Y represent the horizontal and vertical coordinates of the target game node in the game world; W1 and H1 represent the width and height of the display interface, respectively. ′ and H ′ W1 and W2 represent the width and height of the target canvas, respectively; W3 and H3 represent the width and height of the bounding box corresponding to the target game node, respectively; and α represents the device pixel ratio of the target device.

[0046] After generating the target animation in the target canvas based on the frame image data and the graphic attribute information, and rendering the target animation to the target game node, the following steps can be taken: loading the static image corresponding to each frame of image data into the target canvas; configuring the static image corresponding to each frame of image data based on the frame object to obtain multiple frames of animation pictures; configuring the multiple frames of animation pictures based on the animation object to obtain the target animation; converting the target animation into texture data recognizable by the game engine; and applying the texture data to the display component corresponding to the target game node to complete the animation rendering of the target game node.

[0047] It can be understood that the key to the above animation rendering is to create a Canvas element, and then generate an animation in the Canvas element using the frame image data and the graphic attribute information in the APNG file, and render the animation to the target game node of the game engine.

[0048] Specifically, the system can first obtain the accurate coordinates of the target game node in the game world, which is the position of the node in the game scene; the bounding box corresponding to the target game node can be determined according to the bounding box, which is a term in three-dimensional graphics, used to describe the size of the node, i.e. the width and height of the node in the game world; in addition, the device pixel ratio of the target device displaying the game picture and the size of the current display interface need to be understood, which is to adapt to screens of different resolutions and optimize the rendering effect. By calculating the percentage position of the target canvas in the display interface through the formula, it can be ensured that no matter the resolution of the screen, the canvas can be accurately placed according to the current screen size; by calculating the width and height of the target canvas through the formula, a canvas size that adapts to the current device and screen size can be generated, and considering the pixel density of the device, the image quality and performance on high-resolution devices can be ensured.

[0049] Based on the above calculated position information and size information, a Canvas element will be configured and created on the target game node, which will be placed at the correct position and its size will accurately adapt to the size of the target node and the characteristics of the game display interface.

[0050] The image data of each frame in the APNG file is converted into PNG format in advance because the Canvas API is better at handling PNG format images, and the conversion process ensures the clarity and color accuracy of each frame. When generating the animation, the converted PNG images of each frame can be loaded into the created Canvas element first. Each frame object contains specific attributes of that frame, such as display time, position, size, etc. Based on these attributes, PNG images are configured one by one on the canvas to accurately position and scale each frame of the animation. By traversing each frame object, the coherence and smoothness of the animation are ensured. After configuring the basic information of each frame, the entire animation flow can be integrated according to the loop count information of the APNG object to determine when to repeat or stop playing, thereby generating a complete and looped target animation.

[0051] After that, the generated multi-frame animation pictures can be converted into WebGL recognizable texture data, because game engines, especially Cocos engine based on WebGL, are better at handling and rendering texture data than raw image file formats. This conversion process usually involves reading and adjusting the format of image pixels to adapt to the rendering pipeline of the game engine. After converting the animation pictures into textures, they can be rendered more efficiently in the game engine. The converted texture data is bound to the display component on the target game node, such as the Sprite component. This step is crucial for presenting dynamic content to the player. Once bound, the game engine will dynamically update the texture of the picture component according to the animation playback logic in the rendering loop, thereby rendering the target animation in real time on the game interface and achieving the visual dynamic effect.

[0052] Through the above series of implementation steps, APNG animations can be effectively integrated into game engines, improving resource loading efficiency and ensuring high-quality rendering of animations, enhancing user gaming experience.

[0053] As an optional implementation, in the case of a static image type of a graphic resource file, the static image can be directly converted into game engine recognizable texture data, and the texture data can be applied to the display component corresponding to the target game node to complete the rendering of the target game node.

[0054] It is understandable that when the system is processing static images rather than dynamic APNG animations, the process of rendering to the target game node is greatly simplified, but it is still necessary to ensure the accuracy and efficiency of steps such as image loading, conversion, and display component configuration. First, load the static image file in PNG, JPG or other formats, convert the loaded static image into WebGL recognizable texture data, and once the texture data is ready, the system will bind it to the display component on the target game node, such as the Sprite component. Before binding the texture, interface adaptation adjustments need to be made to ensure that the static image can properly fill or adapt to the size of the target node, avoiding stretching or distortion, which usually involves image scaling, cropping or maintaining aspect ratio strategies. By configuring the display component, you can ensure that the texture is correctly displayed on the node, including size, position, and rotation angle, etc. After texture binding and interface adaptation, the system will perform real-time rendering. In the rendering loop of the game engine, the static image is drawn to the game scene as part of the texture, so that the player can see the loaded image immediately.

[0055] Considering that nodes in the game engine may be destroyed or updated due to player operations, changes in game logic, etc., once the node is invalid, operations on it may cause errors or exceptions, such as memory leaks, rendering failures, etc. Therefore, as an optional implementation, before detecting the type of graphical resource file, the target game node can be verified for validity by the following steps: detecting the validity of the target game node; if the target game node is valid, continue to detect the type of the graphical resource file; if the target game node is invalid, terminate the subsequent process and generate a node exception prompt information.

[0056] Specifically, in the Cocos engine, the validity of a node can be determined by the isValid attribute, which indicates whether the node still exists in the child node list of its parent node or has been marked for destruction. Before attempting to detect and load resources, the system checks the isValid attribute of the target game node. If this attribute is true, the node is considered valid and the system will continue the resource type detection process. If isValid is false, it means that the node has been destroyed or is no longer needed, at which point the system will terminate the subsequent resource loading and rendering process and generate a node exception prompt information, which helps to avoid unnecessary resource loading and reduce potential performance problems and memory consumption. Optionally, when the node is detected to be invalid, the system can output error information to the console or use a log system to record the exception situation. Considering user experience, a friendly UI prompt can be designed to inform users or developers why some resources failed to load or display, for example, the reason why the avatar frame did not appear normally may be that the node was closed or destroyed before the resource loading was completed.

[0057] In the embodiments of the present application, by detecting the file type in the initial stage of loading the graphic resource, the animation format file is distinguished from the static image, and corresponding processing strategies can be adopted according to different formats, which is the basis for ensuring the correctness of the subsequent animation playing and static image rendering process; for the animation format file, by extracting the corresponding frame image data and graphic attribute information, the complex animation file can be converted into a series of frame data and metadata that are easy to process, and then the playing order, delay time and cycle number of each frame are accurately controlled, so that more realistic and smooth animation effect is realized; then, a canvas is dynamically created for the corresponding target game node, and an animation is generated in the canvas based on the parsed frame image data and graphic attribute information, and the animation is converted into texture data recognizable by the game engine, and the texture data is applied to the display component corresponding to the game node, so that the animation rendering of the game node is completed. The technical problem that the game engine in the related scheme can only render static images and cannot normally render APNG and other format animations is effectively solved.

[0058] Embodiment 2

[0059] According to the embodiments of the present application, a graphic resource rendering device in a game engine for implementing the graphic resource rendering method in the game engine in embodiment 1 is also provided, as shown in Figure 2 The graphic resource rendering device in the game engine at least includes a detection module 21, an analysis module 22 and a rendering module 23, wherein:

[0060] The detection module 21 is used to obtain the graphic resource file corresponding to the target game node in the game engine, and detect the type of the graphic resource file.

[0061] The analysis module 22 is used to analyze the frame image data and the graphic attribute information in the graphic resource file when the type of the graphic resource file is a preset animation format.

[0062] The rendering module 23 is used to create a target canvas in the target game node, generate a target animation in the target canvas based on the frame image data and the graphic attribute information, and render the target animation to the target game node.

[0063] The functions of each module of the graphic resource rendering device in the game engine will be described below in combination with the specific implementation process.

[0064] Firstly, the detection module needs to obtain the graphic resource file corresponding to the target game node in the game engine, and detect the type of the graphic resource file.

[0065] As an optional implementation, when detecting the type of the graphic resource file, the following method can be used: detecting whether the header signature of the graphic resource file matches a preset animation format signature; in the case where the header signature of the graphic resource file matches the animation format signature, determining that the type of the graphic resource file is the preset animation format; in the case where the header signature of the graphic resource file does not match the animation format signature, determining that the type of the graphic resource file is a static image.

[0066] In the case where it is detected that the type of the graphic resource file is the preset animation format, the parsing module needs to further parse the frame image data and the graphic attribute information in the graphic resource file, and the graphic attribute information usually includes frame image attribute information, frame control attribute information and animation attribute information.

[0067] As an optional implementation, when parsing the frame image data and the graphic attribute information in the graphic resource file, the frame image attribute information can be first determined from the image header data block of the graphic resource file, and the frame control attribute information can be determined from the frame control block of the graphic resource file, and the frame image attribute information and the frame control attribute information are stored in a frame object, wherein the frame image attribute information at least includes frame image size, and the frame control attribute information at least includes display time, display position and display size of the frame image; then, the animation attribute information can be determined from the animation control block in the graphic resource file, and the animation attribute information is stored in an animation object, wherein the animation attribute information at least includes animation cycle number and total frame number of the animation; and then, the frame image data can be determined from the frame data block or the image data block in the graphic resource file, and each frame image data is encapsulated as a static image based on a binary large object.

[0068] In order to improve the efficiency of graphic processing, after the frame image data and the graphic attribute information in the graphic resource file are parsed, the frame image data and the graphic attribute information can be stored in a cache database. In this way, in the next graphic resource rendering task, before the frame image data and the graphic attribute information in the graphic resource file are executed, it can be detected whether the frame image data and the graphic attribute corresponding to the graphic resource file exist in the cache database, if they exist, the frame image data and the graphic attribute information can be directly called, and if they do not exist, the frame image data and the graphic attribute information in the graphic resource file are continued to be parsed.

[0069] After the relevant data are parsed and saved, a target canvas can be created in the target game node, a target animation can be generated in the target canvas based on the frame image data and the graphic attribute information, and the target animation can be rendered to the target game node.

[0070] As an optional implementation, the target canvas can be created in the target game node in the following manner: obtaining game world coordinates corresponding to the target game node and boundary box size information corresponding thereto, and obtaining device pixel ratio of a target device used for displaying the game picture and display interface size information; determining position information of the target canvas in the display interface according to the game world coordinates and the display interface size information; determining a first ratio between the boundary box size information and the display interface size information, and determining a second ratio between resolution size of the target canvas and the device pixel ratio of the target device, and determining size information of the target canvas based on the first ratio and the second ratio; and configuring the target canvas in the target game node based on the position information and the size information of the target canvas.

[0071] After generating the target animation in the target canvas based on the frame image data and the graphic attribute information, and rendering the target animation to the target game node, the following steps can be taken: loading the static image corresponding to each frame of image data into the target canvas; configuring the static image corresponding to each frame of image data based on the frame object to obtain a plurality of frames of animation pictures; configuring the plurality of frames of animation pictures based on the animation object to obtain the target animation; converting the target animation into texture data recognizable by the game engine; and applying the texture data to the display component corresponding to the target game node to complete animation rendering of the target game node.

[0072] Through the above series of implementation steps, the APNG animation can be effectively integrated into the game engine, not only improving the efficiency of resource loading, but also ensuring high-quality rendering of the animation and enhancing the user's game experience.

[0073] As an optional implementation, in the case where the type of the graphic resource file is a static image, the static image can be converted into texture data recognizable by the game engine, and the texture data can be applied to the display component corresponding to the target game node to complete rendering of the target game node.

[0074] Considering that the nodes in the game engine can be destroyed or updated due to player operations, changes in game logic, and the like, once the nodes are invalid, operations thereon can cause errors or exceptions, such as memory leakage, rendering failure, and the like. Therefore, as an optional implementation, before detecting the type of the graphic resource file, the target game node can be verified to be in a valid state in the following manner: detecting validity of the target game node; in the case where the target game node is valid, continuing to detect the type of the graphic resource file; in the case where the target game node is invalid, terminating the subsequent process, and generating node exception prompt information.

[0075] It should be noted that each module in the graphics resource rendering device in the game engine in the embodiments of the present application corresponds to each implementation step of the graphics resource rendering method in the game engine in Embodiment 1. Since Embodiment 1 has been described in detail, the details not embodied in this embodiment can be referred to Embodiment 1, and will not be described in detail here.

[0076] Embodiment 3

[0077] According to the embodiments of the present application, a computer program product is also provided, which includes a computer program. When the computer program is executed by a processor, the graphics resource rendering method in the game engine in Embodiment 1 is implemented.

[0078] According to the embodiments of the present application, a non-volatile storage medium is also provided, which includes a stored computer program. The device in which the non-volatile storage medium is located executes the graphics resource rendering method in the game engine in Embodiment 1 by running the computer program.

[0079] According to the embodiments of the present application, a processor is also provided, which is used to run a computer program. When the computer program is run, the graphics resource rendering method in the game engine in Embodiment 1 is executed.

[0080] According to the embodiments of the present application, an electronic device is also provided, which includes a memory and a processor. The memory stores a computer program, and the processor is configured to execute the graphics resource rendering method in the game engine in Embodiment 1 by the computer program.

[0081] Specifically, when the computer program is run, the following steps are implemented: obtaining a graphics resource file corresponding to a target game node in a game engine, and detecting the type of the graphics resource file; in the case that the type of the graphics resource file is a preset animation format, parsing frame image data and graphics attribute information in the graphics resource file; creating a target canvas in the target game node, generating a target animation in the target canvas based on the frame image data and the graphics attribute information, and rendering the target animation to the target game node.

[0082] As an optional implementation, the above electronic device can exist in the form of a mobile terminal, a computer terminal or a similar computing device. Figure 3 A hardware structure block diagram of an electronic device for implementing the graphics resource rendering method in the game engine is shown. As shown in FIG. 8, the electronic device includes a processor 801, a memory 802 and a bus 803. Figure 3As shown, the electronic device 30 can include one or more processors 302 (the processor 302 can include, but is not limited to, a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory 304 for storing data, and a transmission device 306 for communication functions. In addition, it can also include a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which can be included as one of the ports of the BUS bus), a network interface, a power supply and / or a camera. Those skilled in the art can understand that Figure 3 The structure shown is only schematic, which does not limit the structure of the above-mentioned electronic device. For example, the electronic device 30 can also include more or fewer components than those shown in the figure, or have a different configuration from that shown in the figure. Figure 3 The structure shown is only schematic, which does not limit the structure of the above-mentioned electronic device. For example, the electronic device 30 can also include more or fewer components than those shown in the figure, or have a different configuration from that shown in the figure. Figure 3 The structure shown is only schematic, which does not limit the structure of the above-mentioned electronic device. For example, the electronic device 30 can also include more or fewer components than those shown in the figure, or have a different configuration from that shown in the figure.

[0083] It should be noted that the one or more processors 302 and / or other data processing circuits described above can be referred to herein as "data processing circuits" in general. The data processing circuit can be embodied in whole or in part as software, hardware, firmware, or any combination thereof. In addition, the data processing circuit can be a single independent processing module, or all or part of any one of the other elements combined into the electronic device 30. As referred to in the embodiments of the present application, the data processing circuit serves as a processor to control (for example, selection of a variable resistance terminal path connected to an interface).

[0084] The memory 304 can be used to store software programs and modules of application software, such as program instructions / data storage devices corresponding to the graphic resource rendering method in the game engine in the embodiments of the present application. The processor 302 executes various functional applications and data processing by running the software programs and modules stored in the memory 304, that is, implements the vulnerability detection method of the application program described above. The memory 304 can include a high-speed random access memory, and can also include a non-volatile memory, such as one or more magnetic storage devices, flash memories, or other non-volatile solid-state memories. In some examples, the memory 304 can further include a memory remotely arranged with respect to the processor 302, which can be connected to the electronic device 30 through a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and a combination thereof.

[0085] The transmission device 306 is configured to receive or send data via a network. The network can include a wireless network provided by a communication provider of the electronic device 30. In one example, the transmission device 306 includes a network interface controller (NIC) that can connect to other network devices through a base station to communicate with the Internet. In one example, the transmission device 306 can be a radio frequency (RF) module that is configured to communicate with the Internet wirelessly.

[0086] The display can be a liquid crystal display (LCD) that is touch screen, for example, which can enable a user to interact with a user interface of the electronic device 30.

[0087] The above-mentioned embodiment numbers are only for description, and do not represent the advantages or disadvantages of the embodiments.

[0088] In the above-mentioned embodiments of the present application, the description of each embodiment has its own focus, and the parts not described in detail in a certain embodiment can be referred to the relevant description of other embodiments.

[0089] In the several embodiments provided in the present application, it should be understood that the disclosed technology can be implemented in other ways. Of course, the embodiment described above is only illustrative, and the division of units can be a logical function division, and actual implementation can have another division manner, for example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the units shown or discussed can be indirect coupling or communication connection through some interfaces, units or modules, which can be electrical or other forms.

[0090] The units described as separate components can or can not be physically separate, and the components shown as units can or can not be physical units, that is, they can be located in one place, or they can be distributed on multiple units. Part or all of the units can be selected according to actual needs to achieve the purpose of the present embodiment.

[0091] In addition, each functional unit in each embodiment of the present application can be integrated in one processing unit, or each unit can exist physically, or two or more units can be integrated in one unit. The above integrated unit can be realized in the form of hardware or in the form of a software functional unit.

[0092] The integrated unit, if implemented in the form of a software function unit and sold or used as an independent product, can be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the present application essentially or say the part that contributes to the prior art or the whole or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server or a network device, etc.) to execute all or part of the steps of the embodiments of the present application. The aforementioned storage medium includes: a U disk, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and various media that can store program codes.

[0093] The above is only the preferred embodiment of the present application, and it should be pointed out that for those skilled in the art, without departing from the principles of the present application, a number of improvements and refinements can be made, which should be considered as the protection scope of the present application.

Claims

1. A method for rendering graphics resources in a game engine, characterized in that, include: Obtain the graphics resource file corresponding to the target game node in the game engine, and detect the type of the graphics resource file; When the type of the graphic resource file is a preset animation format, the frame image data and graphic attribute information in the graphic resource file are parsed. A target canvas is created in the target game node, a target animation is generated in the target canvas based on the frame image data and the graphic attribute information, and the target animation is rendered to the target game node.

2. The method according to claim 1, characterized in that, Detecting the type of the graphics resource file includes: Detect whether the header signature of the graphic resource file matches the preset animation format signature; If the header signature of the graphic resource file matches the animation format signature, the type of the graphic resource file is determined to be a preset animation format; If the header signature of the graphic resource file does not match the animation format signature, the type of the graphic resource file is determined to be a static image.

3. The method according to claim 1, characterized in that, The graphic attribute information includes frame image attribute information, frame control attribute information, and animation attribute information. Parsing the frame image data and graphic attribute information in the graphic resource file includes: The frame image attribute information is determined from the image header data block of the graphics resource file, and the frame control attribute information is determined from the frame control block of the graphics resource file. The frame image attribute information and the frame control attribute information are stored in a frame object. The frame image attribute information includes at least the frame image size, and the frame control attribute information includes at least the frame image display time, display position, and display size. The animation attribute information is determined from the animation control block in the graphics resource file and stored in the animation object. The animation attribute information includes at least: the number of animation loops and the total number of animation frames. The frame image data is determined from the frame data block or image data block in the graphics resource file, and each frame image data is encapsulated into a static image based on a binary large object.

4. The method according to claim 1, characterized in that, Creating a target canvas in the target game node includes: Obtain the game world coordinates and corresponding bounding box size information corresponding to the target game node, and obtain the device pixel ratio and display interface size information of the target device used to display the game screen; The position information of the target canvas in the display interface is determined based on the game world coordinates and the display interface size information; A first ratio is determined between the bounding box size information and the display interface size information, and a second ratio is determined between the resolution size of the target canvas and the device pixel ratio of the target device. The size information of the target canvas is determined based on the first ratio and the second ratio. The target canvas is configured in the target game node based on the position and size information of the target canvas.

5. The method according to claim 3, characterized in that, Based on the frame image data and the graphic attribute information, a target animation is generated in the target canvas, and the target animation is rendered to the target game node, including: Load the static image corresponding to each frame of image data into the target canvas; Based on the frame object, configure the static image corresponding to each frame of image data to obtain a multi-frame animation; The target animation is obtained by configuring the multi-frame animation based on the animation object; The target animation is converted into texture data that the game engine can recognize; The texture data is applied to the display component corresponding to the target game node to complete the animation rendering of the target game node.

6. The method according to claim 1, characterized in that, Before detecting the type of the graphic resource file, the method further includes: Detect the validity of the target game node; If the target game node is valid, continue to detect the type of the graphics resource file; If the target game node is invalid, the subsequent process will be terminated and a node error message will be generated.

7. The method according to claim 1, characterized in that, Before parsing the frame image data and graphic attribute information in the graphic resource file, the method further includes: detecting whether the frame image data and graphic attribute information corresponding to the graphic resource file exist in the cache database; if they exist, directly calling the frame image data and graphic attribute information; if they do not exist, parsing the frame image data and graphic attribute information in the graphic resource file. After parsing the frame image data and graphic attribute information in the graphic resource file, the method further includes storing the frame image data and graphic attribute information in the cache database.

8. The method according to claim 2, characterized in that, The method further includes: If the type of the graphics resource file is a static image, the static image is converted into texture data that the game engine can recognize; The texture data is applied to the display component corresponding to the target game node to complete the rendering of the target game node.

9. A graphics resource rendering device for a game engine, characterized in that, include: The detection module is used to obtain the graphics resource file corresponding to the target game node in the game engine and detect the type of the graphics resource file; The parsing module is used to parse the frame image data and graphic attribute information in the graphic resource file when the type of the graphic resource file is a preset animation format; The rendering module is used to create a target canvas in the target game node, generate a target animation in the target canvas based on the frame image data and the graphic attribute information, and render the target animation to the target game node.

10. An electronic device, characterized in that, include: A memory and a processor, wherein the memory stores a computer program, and the processor is configured to execute, via the computer program, a graphics resource rendering method in a game engine according to any one of claims 1 to 8.