An efficient touch allocation method and device based on cocos2dx
The Cocos2dx-based method optimizes touch control allocation by creating a root node, dividing the scene, and multi-level filtering to distribute touch events, addressing performance and user experience issues in game engines.
Patent Information
- Application Number
- CN202111570654.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-21
- Publication Date
- 2025-07-15
- Estimated Expiration
- 2041-12-21
AI Technical Summary
When existing game engines add touch functions to a large number of sprite nodes, they cause increased device performance pressure, affecting product fluency and user experience.
Using a cocos2dx-based method, by creating a root node and binding event listening, the scene is divided into N regions, saving the horizontal coordinates of the child nodes, filtering the target nodes in multiple levels, and assigning touch events to the nodes with the highest priority.
Reduces the equipment performance pressure, improves touch distribution efficiency and user experience, and enhances product fluency.
Smart Images

Figure CN114392547B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of games, and particularly to an efficient touch allocation method and device based on cocos2dx. Background Art
[0002] Under the development environment provided by common game engines currently, to add a touch function to a sprite node, a listener needs to be added to receive events from users. When there are a large number of touchable sprite nodes in a game scene, event listeners need to be added to each sprite node, which will not only increase the performance pressure on the device, but also affect the smoothness of the product and the user experience. Summary of the Invention
[0003] (1) Technical Problems to be Solved
[0004] To solve the above problems of the prior art, the present invention provides an efficient touch allocation method and device based on cocos2dx, which can reduce the performance pressure on the device and achieve more efficient touch allocation, thereby improving the smoothness of the product and the user experience.
[0005] (2) Technical Solutions
[0006] To achieve the above object, a technical solution adopted by the present invention is as follows:
[0007] An efficient touch allocation method based on cocos2dx includes the steps of:
[0008] S1. Create a root node and bind an event listener;
[0009] S2. Divide the current scene in a preset direction, delimit N regions, and create a table with a length of N, and save the abscissas of all child nodes of the root node into the table;
[0010] S3. When a touch operation of a user is detected through the root node, perform multi-level screening on all child nodes according to the data in the table and preset rules to obtain a target node, and allocate the touch event of the root node to the target node.
[0011] To achieve the above object, another technical solution adopted by the present invention is as follows:
[0012] An efficient touch allocation device based on cocos2dx includes a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the program, the following steps are implemented:
[0013] S1. Create a root node and bind an event listener;
[0014] S2. Divide the current scene in a preset direction, delimit N regions, create a table with a length of N, and save the abscissas of all child nodes of the root node into the table;
[0015] S3. When a touch operation of the user is monitored through the root node, perform multi-level screening on all child nodes according to the data in the table and preset rules to obtain a target node, and assign the touch event of the root node to the target node.
[0016] (III) Beneficial effects
[0017] The beneficial effects of the present invention are as follows: By creating a root node and binding event monitoring; dividing the current scene in a preset direction, delimit N regions, create a table with a length of N, and save the abscissas of all child nodes of the root node into the table; when a touch operation of the user is monitored through the root node, perform multi-level screening on all child nodes according to the data in the table and preset rules to obtain a target node, and assign the touch event of the root node to the target node, not only reducing the performance pressure of the device, but also making the touch allocation more efficient, thereby improving the fluency of the product and the user experience. Description of the drawings
[0018] Figure 1 is a flowchart of an efficient touch allocation method based on cocos2dx according to an embodiment of the present invention;
[0019] Figure 2 is a schematic diagram of the overall structure of an efficient touch allocation device based on cocos2dx according to an embodiment of the present invention.
[0020]
Description of the reference numerals
[0021] 1: Efficient touch allocation device based on cocos2dx;
[0022] 2: Memory;
[0023] 3: Processor. Detailed implementation manners
[0024] In order to better explain the present invention for easy understanding, the present invention will be described in detail below with reference to the drawings through specific implementation manners.
[0025] Embodiment 1
[0026] Please refer to Figure 1 , an efficient touch allocation method based on cocos2dx, including the steps:
[0027] S1. Create a root node and bind event monitoring;
[0028] S2. Divide the current scene in a preset direction, delimit N regions, create a table with a length of N, and save the abscissas of all child nodes of the root node into the table.
[0029] Step S2 is specifically as follows:
[0030] Divide the current scene equally in width with a fixed pixel interval length horizontally, delimit N regions, create a table with a length of N in memory, and save the abscissas of all child nodes of the root node into the table.
[0031] S3. When a touch operation of the user is monitored through the root node, perform multi-level screening on all child nodes according to the data in the table and preset rules to obtain a target node, and assign the touch event of the root node to the target node.
[0032] Step S3 includes:
[0033] S31. When a touch operation of the user is monitored through the root node, perform a first screening according to the data in the table to obtain all child nodes in the region corresponding to the abscissa of the touch operation.
[0034] S32. Perform a second screening according to all child nodes in this region, respectively judge whether the coordinates of the touch operation are located within the bounding boxes of each child node in this region. If so, record and obtain a set of child nodes.
[0035] S33. Obtain the node with the highest priority according to the levels and rendering sequences of each child node in the set of child nodes, and use it as the target node.
[0036] S34. Assign the touch event of the root node to the target node.
[0037] Embodiment 2
[0038] The difference between this embodiment and Embodiment 1 is that this embodiment will further illustrate how the above-mentioned efficient touch allocation method based on cocos2dx of the present invention is implemented in combination with a specific application scenario:
[0039] 1. Create a root node and bind an event listener, which is also the only touch event listener in the current scene. The rest of the sprite nodes in the scene are child nodes of the root node.
[0040] 2. Divide the current scene equally in width with a horizontal INTERVAL_LENGTH (fixed pixel interval length), delimit N regions, and create a table (mapTable) with a length of N in memory for saving data.
[0041] 3. When initializing the scene, obtain all the child nodes of the root node, calculate the area where each child node is located by rounding down the x - coordinate of each child node divided by INTERVAL_LENGTH, and then save it to the corresponding position in the mapTable;
[0042] 3.1. When a touch operation of the user is detected through the root node, perform a first - stage screening according to the data in the table to obtain all the child nodes in the area corresponding to the abscissa of the touch operation;
[0043] 3.2. Perform a second - stage screening based on all the child nodes in this area, and respectively determine whether the coordinates of the touch operation are within the bounding boxes of each child node in this area. If so, record the obtained set of child nodes;
[0044] 3.3. According to the levels and rendering order of each child node in the set of child nodes, obtain the node with the highest priority and use it as the target node;
[0045] 3.4. Assign the touch event of the root node to the target node.
[0046] Specifically, first, through the first - stage screening, determine which nodes are in the area corresponding to the x - coordinate of the touch operation. Then, through the second - stage screening, determine which nodes' bounding boxes the coordinates of the touch operation are within. Finally, through the third - stage screening, obtain the node with the highest priority according to the levels and rendering order of the nodes. Through multi - level screening, the efficiency and speed of touch allocation are improved.
[0047] Embodiment III
[0048] Please refer to Figure 2 , an efficient touch allocation device 1 based on cocos2dx, including a memory 2, a processor 3, and a computer program stored on the memory 2 and executable on the processor 3. When the processor 3 executes the program, it implements each step in Embodiment I.
[0049] The above are only the embodiments of the present invention, and do not limit the patent scope of the present invention. All equivalent transformations made using the content of the specification and drawings of the present invention, or directly or indirectly applied in related technical fields, are similarly included in the patent protection scope of the present invention.
Claims
1. An efficient touch allocation method based on cocos2dx, characterized in that Including the steps: S1. Create a root node and bind an event listener. The root node is the only touch event listener in the current scene, and the rest of the sprite nodes in the current scene are child nodes of the root node; S2. Divide the current scene in a preset direction, delimit N regions, and create a table with a length of N. Save the abscissas of all child nodes of the root node into the table; S3. When a touch operation of the user is detected through the root node, perform multi-level screening on all child nodes according to the data in the table and preset rules to obtain a target node, and assign the touch event of the root node to the target node; Step S3 includes: S31. When a touch operation of the user is detected through the root node, perform a first screening according to the data in the table to obtain all child nodes in the region corresponding to the abscissa of the touch operation; S32. Perform a second screening according to all child nodes in this region, and respectively determine whether the coordinates of the touch operation are within the bounding boxes of each child node in this region. If so, record and obtain a set of child nodes; S33. Obtain the node with the highest priority according to the levels and rendering sequences of the child nodes in the set of child nodes, and use it as the target node; S34. Assign the touch event of the root node to the target node.
2. The efficient touch allocation method based on cocos2dx according to claim 1, characterized in that Step S2 is specifically: Divide the current scene equally in width at a fixed pixel interval length horizontally, delimit N regions, and create a table with a length of N in memory. Save the abscissas of all child nodes of the root node into the table.
3. An efficient touch allocation device based on cocos2dx, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, When the processor executes the program, the following steps are implemented: S1. Create a root node and bind an event listener; S2. Divide the current scene in a preset direction, delimit N regions, and create a table with a length of N. Save the abscissas of all child nodes of the root node into the table; S3. When a touch operation of the user is detected through the root node, perform multi-level screening on all child nodes according to the data in the table and preset rules to obtain a target node, and assign the touch event of the root node to the target node; Step S3 includes: S31. When a touch operation of the user is detected through the root node, perform a first screening according to the data in the table to obtain all child nodes in the region corresponding to the abscissa of the touch operation; S32. Perform a second screening according to all child nodes in this region, and respectively determine whether the coordinates of the touch operation are within the bounding boxes of each child node in this region. If so, record and obtain a set of child nodes; S33. Obtain the node with the highest priority according to the levels and rendering sequences of the child nodes in the set of child nodes, and use it as the target node; S34. Assign the touch event of the root node to the target node.
4. The high-efficiency touch allocation device based on cocos2dx according to claim 3, characterized in that Step S2 is specifically: Divide the current scene equally in width at a fixed pixel interval length horizontally, delimit N regions, and create a table with a length of N in memory. Save the abscissas of all child nodes of the root node into the table.