What is CCARRAY_FOREACH in coccos2d?

不问归期 提交于 2019-12-23 09:11:19

问题


I see a macro CCARRAY_FOREACH in coccos2d, actually what does it? can we do alternative solution instead of it?i am using following code for spriteBatchNode?

     CCARRAY_FOREACH([spriteBatch children], sprite)
{

    ...................
}

回答1:


it is a macro for looping through each object inside a CCArray... an alternative would be objective-c's foreach for (object in array) that goes like this:

for (CCSprite *sprite in [spriteBatch children]) {
    ...
}

this is for NSArray and NSMutableArray but i think it should work fine for CCArray as well.




回答2:


The other answer is actually wrong. CCARRAY_FOREACH isn't a macro for fast enumeration, it is a replacement for fast enumeration for CCArrays. CCARRAY_FOREACH is a tiny bit faster than fast enumeration on a NS(Mutable)Array (about 10%), so better use it if you are using CCArrays.
Check the CCArray.h header to see what the macro actually is.



来源:https://stackoverflow.com/questions/4872855/what-is-ccarray-foreach-in-coccos2d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!