cocos2dx 4.0動畫創建

cocos2dx 4.0動畫創建

直接上代碼

	//創建紋理
	auto texture= Director::getInstance()->getTextureCache()->addImage("frame3/deathboom.png");
	//自己設置紋理上面的幀
	auto frame0 = SpriteFrame::createWithTexture(texture, Rect(0.0f, 92.0f * 0.0f, 94.0f, 92.0f));
	auto frame1 = SpriteFrame::createWithTexture(texture, Rect(0.0f, 92.0f * 1.0f, 94.0f, 92.0f));
	auto frame2 = SpriteFrame::createWithTexture(texture, Rect(0.0f, 92.0f * 2.0f, 94.0f, 92.0f));
	auto frame3 = SpriteFrame::createWithTexture(texture, Rect(0.0f, 92.0f * 3.0f, 94.0f, 92.0f));
	auto frame4 = SpriteFrame::createWithTexture(texture, Rect(0.0f, 92.0f * 4.0f, 94.0f, 92.0f));
	auto frame5 = SpriteFrame::createWithTexture(texture, Rect(0.0f, 92.0f * 5.0f, 94.0f, 92.0f));
	//生成一個動畫數組並放入動畫幀
	Vector<SpriteFrame *> arr;
	arr.pushBack(frame0);
	arr.pushBack(frame1);
	arr.pushBack(frame2);
	arr.pushBack(frame3);
	arr.pushBack(frame4);
	arr.pushBack(frame5);
	//創建動畫信息
	Animation * amt = Animation::createWithSpriteFrames(arr, 0.2f);
	//創建動畫
	Animate * amt2 = Animate::create(amt);
	//創建精靈
	auto sprite2 = Sprite::createWithSpriteFrame(frame0 );
	//將精靈放入場景
	addChild(sprite2);
	//這裏默認只播放一次
	sprite2->runAction(amt2);
	/**
	* 播放多次的代碼
	* Repeat* repeat = Repeat::create(amt, 10);
	* sprite2->runAction(repeat);
	*/

關於老版本的cocos2d創建動畫可以參考https://blog.csdn.net/freebazzi/article/details/27639001這一片博文

最後希望大家可以加入遊戲交流羣:859055710

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章