以下所用方法在#include <stdarg.h>Animation* MyAnimation::createAnimation(char* fileName, ...)
{
//定义指向参数列表的变量
va_list arg_ptr;
//把上面这个变量初始化.即让它指向参数列表
va_start(arg_ptr, fileName);
Animation* animation = Animation::create();
char* name = fileName;
while (name != nullptr)
{
animation->addSpriteFrameWithFile(name);
//获取arg_ptr指向的当前参数.这个参数的类型由va_arg的第2个参数指定
name = va_arg(arg_ptr, char*);
}
//结束时释放
va_end(arg_ptr);
return animation;
}
本文介绍了一个使用 C++ 实现的动画创建方法,通过 va_list 处理不定数量的参数,为动画对象添加帧文件。此方法允许开发者灵活地指定多个帧文件名。
771

被折叠的 条评论
为什么被折叠?



