Cocos2d-x 捕鱼达人动态水纹效果

这篇博客介绍了如何使用Cocos2d-x游戏引擎来创建捕鱼达人游戏中常见的动态水纹效果,包括涟漪效果的实现。文章通过分享C++代码片段展示了具体的实现过程。
摘要由CSDN通过智能技术生成

2.2.2版本亲测可用,效果如下:

该效果原作不详,记得曾经code4app网站上看到过该效果,原作为OC语言所写,后被改成C++,作者也不详....

下面为代码:

pgeRippleSprite.h文件

//
//  pgeRippleSprite.h
//  test2dx
//
//  Created by limeng on 14-1-16.
//
//

#ifndef __test2dx__pgeRippleSprite__
#define __test2dx__pgeRippleSprite__

#include 
   
   
    
    
#include 
    
    
     
     
//
//  pgeRippleSprite.h
//  rippleDemo
//
//  Created by Lars Birkemose on 02/12/11.
//  Copyright 2011 Protec Electronics. All rights reserved.
//
// --------------------------------------------------------------------------
// import headers


// porting to cplusplus by wanghong.li (wanghong.li1029@163.com)on 04/01/12
// All rights reserved


#include "cocos2d.h"
#include 
     
     
      
      
#include "ccTypes.h"

USING_NS_CC;

// --------------------------------------------------------------------------
// defines


#define RIPPLE_DEFAULT_QUAD_COUNT_X             60
#define RIPPLE_DEFAULT_QUAD_COUNT_Y             40


#define RIPPLE_BASE_GAIN                        0.1f        // an internal constant


#define RIPPLE_DEFAULT_RADIUS                   500         // radius in pixels
#define RIPPLE_DEFAULT_RIPPLE_CYCLE             0.25f       // timing on ripple ( 1/frequenzy )
#define RIPPLE_DEFAULT_LIFESPAN                 3.6f        // entire ripple lifespan


#define RIPPLE_CHILD_MODIFIER                   2.0f


// --------------------------------------------------------------------------
// typedefs


typedef enum {
    RIPPLE_TYPE_RUBBER,                                     // a soft rubber sheet
    RIPPLE_TYPE_GEL,                                        // high viscosity fluid
    RIPPLE_TYPE_WATER,                                      // low viscosity fluid
} RIPPLE_TYPE;


typedef enum {
    RIPPLE_CHILD_LEFT,
    RIPPLE_CHILD_TOP,
    RIPPLE_CHILD_RIGHT,
    RIPPLE_CHILD_BOTTOM,
    RIPPLE_CHILD_COUNT
} RIPPLE_CHILD;


typedef struct _rippleData {
    bool                    parent;                         // ripple is a parent
    bool                    childCreated[ 4 ];              // child created ( in the 4 direction )
    RIPPLE_TYPE             rippleType;                     // type of ripple ( se update: )
    cocos2d::CCPoint        center;                         // ripple center ( but you just knew that, didn't you? )
    cocos2d::CCPoint        centerCoordinate;               // ripple center in texture coordinates
    float                   radius;                         // radius at which ripple has faded 100%
    float                   strength;                       // ripple strength
    float                   runtime;                        // current run time
    float                   currentRadius;                  // current radius
    float                   rippleCycle;                    // ripple cycle timing
    float                   lifespan;                       // total life span
} rippleData;


// --------------------------------------------------------------------------
// pgeRippleSprite




typedef list
      
      
       
       ::iterator         RIPPLE_DATA_LIST;
typedef list
       
       
         ::reverse_iterator REVERSE_RIPPLE_DATA_LIST; class CCpgeRippleSprite : public cocos2d::CCNode { private: ccV3F_C4B_T2F_Quad m_sQuad; void setTextureRect(const CCRect& rect, bool rotated, const CCSize& untrimmedSize); void setTextureCoords(CCRect rect); void setMyTexture(CCTexture2D *texture); void setBatchNode(CCSpriteBatchNode *pobSpriteBatchNode); CCPoint m_obOffsetPosition; public: CCpgeRippleSprite(); ~CCpgeRippleSprite(); CC_SYNTHESIZE(cocos2d::CCTexture2D*, m_texture, Texture) CC_SYNTHESIZE(int, m_quadCountX, QuadCountX) CC_SYNTHESIZE(int, m_quadCountY, QuadCountY) CC_SYNTHESIZE(int, m_VerticesPrStrip, VerticesPrStrip) CC_SYNTHESIZE(int, m_bufferSize, BuffSize) CC_SYNTHESIZE(cocos2d::CCPoint*, m_vertice, Vertice) CC_SYNTHESIZE(cocos2d::CCPoint*, m_textureCoordinate, TextureCoordinate) CC_SYNTHESIZE(cocos2d::CCPoint*, m_rippleCoordinate, RippleCoordinate) CC_SYNTHESIZE_READONLY(bool*, m_edgeVertice, EdgeVertice) CC_SYNTHESIZE_READONLY_PASS_BY_REF(std::list 
        
          , m_rippleList, RippleList) public: static CCpgeRippleSprite* rippleSpriteWithFile(const char* filename); bool initWithFile(const char* filename); virtual void draw(); void update(float dt); void ad
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值