简体   繁体   中英

FastRemoveObject in CCArray will change the positions of objects?

I was told that if relying on a specific ordering of objects, I should not use the fastRemoveObject methods in CCArray. Cocos2d API references don't show the contents of the method specifically. Can anyone tell me the reason?

Yes, fastRemoveObject changes the order of nodes. It is therefore not recommended unless it really doesn't matter in your case.

What it does is the following:

  • assign object at last index to index of object being removed
  • nil last object
  • decrease array count

That way the array will not have to perform memory operations (hence: fast). But the last object will now be at the index of the removed object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM