Cocos2dx特效 水纹特效1

Cocos2dx特效水纹特效1

DionysosLai 2014-5-15

       判断一个小游戏是否能够很好的吸引人,除了游戏本身的核心玩法吸引人之外。很多时候,是要靠一些小细节来体现。比方说一个打枪类游戏,玩家随便朝四周射击,子弹打到墙壁上面。玩家的随意操作,其实都包含着一种期望的心里。如果游戏能给出子弹打到墙壁的效果,比方说音效、弹痕等,玩家的心里得到满足,自然而然就对游戏的评价更高一点。如果这时,游戏能够在给出角色由于射击后坐力,导致后退,屏幕摇晃等效果。那么,游戏的效果就so perfect 了。

         在很多时候,玩家会随意触摸屏幕,这些触摸大部分是对游戏操作来说是无效,没有任何效果。如果我们能够对玩家的操作给出一些反应,就可以得到很好效果。水纹效果,正是对这中无效操作的一种很好回应。

         这里,我们的水纹效果,其实是使用了一系列动画来实现的,当然可以使用cocos2dx本身自带效果,这个下次再讲。本次,是有动画特效来实现的。

         使用的资源如下:

 http://download.youkuaiyun.com/detail/dionysos_lai/7367545

         然后对这个效果进行了封装了:

         .h文件如下:

/**
*@file BAWaterEffect.h
*@brie 播放水纹特效
*
*详细概述
*
*@author DionysosLai,email: 906391500@qq.com
*@version 1.0
*@data 2014-5-15 9:40
*/

#ifndef __WATER_EFFECT_H__
#define __WATER_EFFECT_H__

#include "cocos2d.h"  
#include "cocos-ext.h"

class WaterEffect : public cocos2d::CCNode  
{  
public:  
	WaterEffect();  
	~WaterEffect();  

	static WaterEffect* create();  
	virtual bool init();  

private:   
	void initData();  
	cocos2d::extension::CCArmature*	createArmature(const char* armatureName, const char* armatureProName);
	void onPlayEffect( cocos2d::extension::CCArmature *pArmature, cocos2d::extension::MovementEventType eventType, const char *animationID );
private:  
	cocos2d::extension::CCArmature* m_arEffect;
public:
	void playEffect(void);

};  

#endif /* defined(__WATER_EFFECT_H__) */  

         .cpp文件如下:

#include "BAWaterEffect.h"

USING_NS_CC;
using namespace cocos2d::ui;
using namespace cocos2d::extension;

WaterEffect::WaterEffect()
{

}

WaterEffect::~WaterEffect()
{

}

WaterEffect* WaterEffect::create()
{
	WaterEffect *pNode = new WaterEffect();  
	if (pNode && pNode->init())  
	{  
		pNode->autorelease();  
		return pNode;  
	}  
	CC_SAFE_DELETE(pNode);  
	return NULL;  
}

bool WaterEffect::init()
{
	if (!CCNode::init())  
	{  
		return false;  
	}  
	initData();  
	return true;  
}

void WaterEffect::initData()
{
	m_arEffect = this->createArmature("WaterAnimation/WaterAnimation.ExportJson", "WaterAnimation");
	m_arEffect->setPosition(ccp(0.f, 0.f));
	this->addChild(m_arEffect, 0);
}

cocos2d::extension::CCArmature* WaterEffect::createArmature( const char* armatureName, const char* armatureProName )
{
	CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo(armatureName);
	CCArmature *armature = CCArmature::create(armatureProName);
	return armature;
}

///@brief 播放水纹效果
///@param[in] 
///@return 
///@author DionysosLai,906391500@qq.com 
///@retval  
///@post 
///@version 1.0 
///@data 2014-5-15 10:22
void WaterEffect::playEffect( void )
{
	m_arEffect->getAnimation()->play("Water_Play");
	m_arEffect->getAnimation()->setMovementEventCallFunc(this, movementEvent_selector(WaterEffect::onPlayEffect));
}

///@brief 检测水纹效果是否播完
///@param[in] 
///@return 
///@author DionysosLai,906391500@qq.com 
///@retval  
///@post 
///@version 1.0 
///@data 2014-5-15 10:23
void WaterEffect::onPlayEffect( cocos2d::extension::CCArmature *pArmature, cocos2d::extension::MovementEventType eventType, const char *animationID )
{
	/// COMPLETE--只有在动作设置为不循环播放时才在动画结束响应一次
	if (eventType == COMPLETE)
	{
		this->removeAllChildren();
	}
}

使用方式如下:在要使用的文件下定义一个函数:      

voidplayWaterEffect(const cocos2d::CCPoint point);

实现方式如下:

///@brief 播放水纹效果
///@param[in] 
///@return 
///@author DionysosLai,906391500@qq.com 
///@retval  
///@post 
///@version 1.0 
///@data 2014-5-15 10:38
void BATVRemote::playWaterEffect( const cocos2d::CCPoint point )
{
	/// 播放水纹效果
	WaterEffect* waterEffect = WaterEffect::create();
	waterEffect->playEffect();
	waterEffect->setPosition(point);
	this->addChild(waterEffect, ZWATER);
}

最后在要用的地方,直接调用函数playWaterEffect即可。

关注用户体验,聚焦精品游戏。



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值