RT,求大神解答一下,Animation要求使用vector…
Vector<Action*> aVect;
auto act1 = MoveBy::create(2.0, Point(100,100));
aVect.pushBack( act1 );
CCLOG("vector size: %zd.", aVect.size());
Map<int, Action*> map1;
auto act2 = act1->clone();
auto act3 = act1->clone();
map1.insert(13, act2);
map1.insert(14, act3);
CCLOG("map size: %zd.", map1.size());
用法和c++的差不多的。
那请问,如果我想把vector当一个属性该咋办呢?是必须得用new初始化吗?
哦。。没事了 多谢!
//数组不行 要用vector
//auto frameArray = Array::create();
//frameArray->retain();
Vector<SpriteFrame*>frameArray;
// 用一个列表保存所有SpriteFrame对象
for(int i = 1; i <= iFrameNum; i++) {
/* 从SpriteFrame缓存池中获取CCSpriteFrame对象 */
frame = frameCache->spriteFrameByName(String::createWithFormat("run%d.png", i)->getCString());
frameArray.pushBack(frame);
}
/* 使用SpriteFrame列表创建动画对象 */
auto animation = Animation::createWithSpriteFrames(frameArray);
animation->setLoops(-1);
animation->setDelayPerUnit(0.1f);
/* 将动画包装成一个动作 */
auto action = Animate::create(animation);
return action;