cocos2d-x的CCArray用法

前端之家收集整理的这篇文章主要介绍了cocos2d-x的CCArray用法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

一.基本用法

1.声明初始化变量

2.添加元素到数组

3.删除元素

4.遍历

1).使用ccarray中的宏进行遍历

1
2
3
4
5
6
7
8
9
10
11
12
//所有的路径节点
CCArray * array CCArray createWithCapacity ( 20 ;
float dt = 1 / ( m_pProperty -> fMoveSpeed ;
CCPoint point ( Crayon-o" style="font-family:inherit; font-size:inherit!important; line-height:inherit!important; height:inherit!important; color:rgb(0, ;
( UINT i 0 ; i < CGlobal getGameMap m_PathNode size ; ++ i )
{
array ( CCMoveTo ( dt Crayon-sy" style="font-family:inherit; font-size:inherit!important; line-height:inherit!important; height:inherit!important; color:rgb(51, point ;
}
//移动完毕的回调
CCCallFunc ( this Crayon-sy" style="font-family:inherit; font-size:inherit!important; line-height:inherit!important; height:inherit!important; color:rgb(51, callfunc_selector CMonster :: onArrive ;
CCSequence pAct CCSequence array ;

3.对于一个CCSprite,我们肯定需要把它addChild到parent上,这样他才能显示出来,这样的话parent上就会有好多child,但是我们要遍历只是其中的一部分(例:场景的地图上有好多种花,我们都会把它们添加到同一个parent上,这时候策划说其中的一种花会被怪物踩死?纳尼….,这个时候我们就需要唉将能被踩死的花加入到parent上时同时加入到一个CCArray中去….),这样我们用的时候遍历这个数组就可以了,而不是遍历这个children!

4.多谢@子龙山人 大大的添加,CCArray还可以内存预分配,比如预先生成一堆子弹,然后加到CCArray中,再从这个CCArray中去重用子弹。这样可以提高游戏效率。消失的子弹只需要设置为Invisible就可以了。这个在做射击类游戏中会大量使用的!

5.还有其他用法?发评论告诉我!

(全文完)


转载自http://blog.justbilt.com/25/

原文链接:https://www.f2er.com/cocos2dx/346270.html

猜你在找的Cocos2d-x相关文章