Method and device for implementing projection based on cocos2d-x
By overlaying and rendering the textures of the projection nodes and processing them with shaders, the problem of projection node overlay and performance consumption was solved, and color value consistency and dynamic effects of the projection display were achieved.
Patent Information
- Application Number
- CN202211072843.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-02
- Publication Date
- 2026-02-24
- Estimated Expiration
- 2042-09-02
AI Technical Summary
Existing technologies suffer from overlapping issues and increased performance consumption when processing shadows of projection nodes, and cannot achieve dynamic effects and aperture edge blurring effects.
The sprite is obtained by overlaying the textures of all projection nodes and then rendering it. The texture is then obtained using RenderTexture and displayed by projection. Combined with shaders, a smooth edge transition is achieved, which avoids the overlay problem and reduces performance overhead.
It achieves consistency in color value and transparency of projection nodes, avoids color overlay and deepening, reduces performance consumption, and simulates dynamic effects and aperture edge blurring effects.
Smart Images

Figure CN115588071B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a method and apparatus for implementing projection based on cocos2d-x. Background Technology
[0002] Currently, the common approach to handling shadows on projection nodes is to simply copy a projection node, set its color to black, and change its transparency. When multiple shadows overlap, the overlapping areas become solid, resulting in less than ideal image quality. Furthermore, the numerous operations involved in destroying and creating projection nodes increase performance overhead. Additionally, this method fails to simulate dynamic effects when the projection node has animations. Since projection displays typically use ClippingNode to trim content outside the projection area, it cannot achieve the desired edge blurring effect. Summary of the Invention
[0003] (a) Technical problems to be solved
[0004] To address the aforementioned problems in the prior art, this invention provides a method and apparatus for projection based on cocos2d-x, which can avoid the superposition problem and reduce performance overhead.
[0005] (II) Technical Solution
[0006] To achieve the above objectives, the present invention adopts the following technical solution:
[0007] A method for implementing projection based on cocos2d-x, including the following steps:
[0008] S1. The sprite is obtained by overlaying the textures of all projection nodes and then rendering them.
[0009] S2. Project and display the sprite.
[0010] To achieve the above objectives, another technical solution adopted by the present invention is as follows:
[0011] An apparatus for implementing projection based on cocos2d-x includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, it performs the following steps:
[0012] S1. The sprite is obtained by overlaying the textures of all projection nodes and then rendering them.
[0013] S2. Project and display the sprite.
[0014] (III) Beneficial Effects
[0015] The beneficial effects of this invention are as follows: Compared with the existing technology of rendering each node separately and then directly overlaying it to change the transparency, which leads to overlaying problems, by overlaying the textures of all projection nodes and then rendering the sprite, the consistency of color values and transparency is guaranteed, thereby avoiding overlaying problems and the color becoming darker and more solid. Moreover, by obtaining the textures and rendering of all projection nodes through RenderTexture, only the textures of the projection nodes are obtained and drawn, and projection is performed according to the sprite. There is no need to create and destroy the projection nodes, which reduces the performance overhead. Attached Figure Description
[0016] Figure 1 This is a flowchart of a method for implementing projection based on cocos2d-x according to an embodiment of the present invention;
[0017] Figure 2 This is a schematic diagram of the overall structure of the device for projection based on cocos2d-x according to an embodiment of the present invention.
[0018] [Explanation of Labels in the Attached Image]
[0019] 1: A device for projection based on cocos2d-x;
[0020] 2: Memory;
[0021] 3: Processor. Detailed Implementation
[0022] To better explain and facilitate understanding of the present invention, the present invention will be described in detail below with reference to the accompanying drawings and specific embodiments.
[0023] Example 1
[0024] Please refer to Figure 1 A method for implementing projection based on cocos2d-x, including the following steps:
[0025] S0. Create a RenderTexture and filter out all projected nodes whose positions are within the display area.
[0026] S1. The sprite is obtained by overlaying the textures of all projection nodes and then rendering them.
[0027] In this embodiment, step S1 specifically includes:
[0028] After overlaying the textures of all projection nodes using RenderTexture, a sprite containing shape, color, and outline information is obtained through unified rendering.
[0029] S2. Project and display the sprite.
[0030] In this embodiment, step S2 specifically includes:
[0031] The sprite is then projected and displayed after the edges are smoothly transitioned using a shader.
[0032] In this embodiment, the smooth edge transition based on the sprite using a shader specifically refers to:
[0033] The distance between the center point and the pixel is calculated using the shader coordinates of the sprite.
[0034] The transparency value is calculated using a smooth step function based on the distance, so that pixels within a preset range have a transparency transition region.
[0035] Specifically, the shader is used to change the properties of the RenderTexture to simulate the effect of shadows, and the edge blurring effect of the aperture is achieved by making the pixels within the preset range have a transparency transition area.
[0036] In this embodiment, the following steps are also included:
[0037] Create a scheduler to update the rendering, updating the texture in the RenderTexture at regular intervals.
[0038] Specifically, simulated motion effects are achieved by updating the texture in the RenderTexture at intervals using the scheduler.
[0039] Example 2
[0040] This embodiment will further illustrate how the above-mentioned method for projection based on cocos2d-x is implemented in conjunction with a specific application scenario:
[0041] 1. Rendering Process
[0042] 1.1 Create a RenderTexture to render shadows;
[0043] 1.2 Create a scheduler to update the rendering, updating the texture in the RenderTexture at regular intervals;
[0044] 1.3 The rendering process filters out all projected nodes whose positions are in front of the light source and whose display range is within the display area.
[0045] 1.4 After overlaying the textures of all projection nodes using RenderTexture, a unified rendering is performed to obtain a sprite containing shape, color, and outline information, thus completing this rendering process;
[0046] 1.5 Wait for the next rendering process, and repeat steps 1.3 and 1.4.
[0047] 2. Shader processing flow
[0048] 2.1 Transfer the sprite containing shape, color, and outline information obtained from the RenderTexture to the shader for processing;
[0049] 2.2 The distance between the center point and the pixel is calculated using shader coordinates based on the sprite;
[0050] 2.3 The transparency value is calculated using a smooth step function based on the distance, so that pixels within the radius from lightRadius to lightRadius+0.05 have a transition region where the transparency changes from 1 to 0, thus completing the shader processing.
[0051] Example 3
[0052] Please refer to Figure 2 A device 1 for projection based on cocos2d-x 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, it implements the steps in Embodiment 1.
[0053] The above description is merely an embodiment of the present invention and does not limit the patent scope of the present invention. Any equivalent modifications made based on the content of the present invention specification and drawings, or direct or indirect applications in related technical fields, are similarly included within the patent protection scope of the present invention.
Claims
1. A method for projection based on cocos2d-x, characterized in that, Including the following steps: S1. The sprite is obtained by overlaying the textures of all projection nodes and then rendering them. S2. Project and display the sprite accordingly; Step S1 is as follows: After overlaying the textures of all projection nodes using RenderTexture, a sprite containing shape, color, and outline information is obtained through unified rendering. Step S2 is as follows: The sprite is then projected and displayed after the edges are smoothly transitioned using a shader. The specific steps of smoothing edge transitions using shaders based on the sprite are as follows: The distance between the center point and the pixel is calculated using the shader coordinates of the sprite. The transparency value is calculated using a smooth step function based on the distance, so that pixels within a preset range have a transparency transition region; Step S1 is preceded by: S0. Create a RenderTexture and filter out all projected nodes whose positions are within the display area.
2. The method for projection based on cocos2d-x according to claim 1, characterized in that, It also includes the following steps: Create a scheduler to update the rendering, updating the texture in the RenderTexture at regular intervals.
3. A device for projection based on cocos2d-x, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it performs the following steps: S1. The sprite is obtained by overlaying the textures of all projection nodes and then rendering them. S2. Project and display the sprite accordingly; Step S1 is as follows: After overlaying the textures of all projection nodes using RenderTexture, a sprite containing shape, color, and outline information is obtained through unified rendering. Step S2 is as follows: The sprite is then projected and displayed after the edges are smoothly transitioned using a shader. The specific steps of smoothing edge transitions using shaders based on the sprite are as follows: The distance between the center point and the pixel is calculated using the shader coordinates of the sprite. The transparency value is calculated using a smooth step function based on the distance, so that pixels within a preset range have a transparency transition region; Step S1 is preceded by: S0. Create a RenderTexture and filter out all projected nodes whose positions are within the display area.
Citation Information
Patent Citations
Extended information display method and device
CN106130886A