Cocos2d-x_播放帧动画

本文介绍了一个使用Cocos2d-x实现的触摸事件处理和精灵动画播放的例子。当用户触摸屏幕时,会触发一个动画效果,并在动画结束后移除相应的精灵。文章详细展示了如何加载精灵帧缓存、创建动画以及执行动画序列。
void HelloWorld::mcallBack(CCObject *pSend)
{
	CCSprite *pSpr = (CCSprite *)pSend;
	pSpr->removeFromParentAndCleanup(true);
}

bool HelloWorld::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{
	CCLOG(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");

	CCPoint pt = pTouch->getLocation();

	CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache();
	cache->addSpriteFramesWithFile("frame_ani/pointer.plist", "frame_ani/pointer.png");

	CCSprite *light = CCSprite::create();
	light->setPosition(pt);
	this->addChild(light);

	CCArray *spriteArray = CCArray::create();
	char str[100] = { 0 };
	for (int i = 1; i <= 9; i++)
	{
		sprintf(str, "pointer/%02d.png", i);
		CCSpriteFrame *frame = cache->spriteFrameByName(str);
		spriteArray->addObject(frame);
	}
	CCAnimation *animation = CCAnimation::createWithSpriteFrames(spriteArray, 0.05f);
	CCAnimate *animate = CCAnimate::create(animation);
	CCFiniteTimeAction *actSeq = CCSequence::create(animate, CCCallFuncO::create(this, callfuncO_selector(HelloWorld::mcallBack), light), NULL);
	light->runAction(actSeq);

	return true;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值