[Pit] CocosCreator used the object pool to recreate the object to create a certain bug when the node was created, and the node used the action system

Conclusion: If the node uses the action system , it is best to stop all the actions of the node when putting the node back into the object pool , otherwise there may be bugs when creating nodes again (there will be no bugs when creating nodes for the first time )

The problem I'm having is:

Create 5 nodes for the first time, then let the nodes move back and forth, and turn the direction at the end

//调转节点方向
node.scaleX *= -1

Then I want to implement the refresh operation, refresh these 5 nodes

I put 5 nodes into the object pool, then create 5 objects again and add them to the node tree

At this time, the problem comes. Some nodes move in the opposite direction to the node direction. It looks like they are walking backwards.

 

After searching for a long time, I didn't find any problems. Finally, I suddenly thought, is it because I didn't stop the node before putting it back into the object pool, which caused this kind of obvious bug?

 

Tried it, it worked, the bug was solved

 

The specific reason is my guess : when using the put method, although CocosCreator will remove the node from the node tree, it will not stop the action of the node, which will cause the action conflict of the node when the next node is created, causing a bug

this.nodePool.put(node);

 

 

 

Guess you like

Origin blog.csdn.net/weixin_41786574/article/details/100886440