Cocos2dx 3.1.1 之 plist制作动画

	动画,可以用flash来制作plist,导出时候有2.x和3.x的区别
	auto cache = SpriteFrameCache::getInstance();
	cache->addSpriteFramesWithFile("anim.plist", "anim.png");

	//用容器来存放每一帧
	Vector vec;
	char name[15];
	memset(name, 0, 15);

	for (int i=1; i<=19; i++) {
		sprintf(name, "anim%04d",i);	//生成每张图片的名字
		vec.pushBack(cache->getSpriteFrameByName(name));
	}
	//容器,每帧执行时间,循环播放
	Animation *animation = Animation::createWithSpriteFrames(vec,0.1f,-1);
	Animate *animate = Animate::create(animation);

	auto * sprite2 = Sprite::create();
	addChild(sprite2);
	sprite2->setPosition(200, 200);
	sprite2->runAction(animate);	//执行动画

你可能感兴趣的:(Cocos2d-x,3.x学习记录)