Cocos2d-x3.1 粒子效果演示样例[通俗易懂]

Cocos2d-x3.1 粒子效果演示样例

大家好,又见面了,我是全栈君。

这里把粒子的几种效果粘出来,以便以后使用

原文地址:http://blog.csdn.net/qqmcy/article/details/37511259

//
//  IntervalLayer.cpp
//  testthirdone
//
//  Created by 杜甲 on 14-7-7.
//
//

#include "IntervalLayer.h"

#define SID_STEP1    100
#define SID_STEP2    101
#define SID_STEP3    102

#define IDC_PAUSE    200

bool IntervalLayer::init()
{
    return true;
}

IntervalLayer::IntervalLayer()
{
    _time0 = _time1 = _time2 = _time3 = _time4 = 0.0f;
    
    auto s = Director::getInstance()->getWinSize();
    
    auto sun = ParticleSun::create();
    sun->setTexture(Director::getInstance()->getTextureCache()->addImage("fire.png"));
    sun->setPosition(Vec2(s.width / 2 -100, s.height / 2));
    
    sun->setTotalParticles(130);
    sun->setLife(5.0f);
    
    this->addChild(sun);
    // timers
    
    
    auto fire = ParticleFire::create();
    fire->setTexture(Director::getInstance()->getTextureCache()->addImage("fire.png"));
    fire->setPosition(Vec2(s.width / 2 + 50, s.height / 2));
    
    fire->setTotalParticles(130);
    fire->setLife(5.0f);
    
    this->addChild(fire);
    
    auto fireworks = ParticleFireworks::create();
    fireworks->setTexture(Director::getInstance()->getTextureCache()->addImage("fire.png"));
    fireworks->setPosition(Vec2(s.width / 2 + 50, s.height / 2 - 200));
    
    fireworks->setTotalParticles(130);
    fireworks->setLife(5.0f);
    
    this->addChild(fireworks);
    
    
    auto galaxy = ParticleGalaxy::create();
    galaxy->setTexture(Director::getInstance()->getTextureCache()->addImage("fire.png"));
    galaxy->setPosition(Vec2( 50, s.height / 2 + 200));
    
    galaxy->setTotalParticles(130);
    galaxy->setLife(5.0f);
    
    this->addChild(galaxy);
    
    

    auto flower = ParticleFlower::create();
    flower->setTexture(Director::getInstance()->getTextureCache()->addImage("fire.png"));
    flower->setPosition(Vec2( 250, s.height / 2 + 200));
    
    flower->setTotalParticles(130);
    flower->setLife(5.0f);
    
    this->addChild(flower);
    
    //流星
    auto meteor = ParticleMeteor::create();
    meteor->setTexture(Director::getInstance()->getTextureCache()->addImage("fire.png"));
    meteor->setPosition(Vec2( 250, 20));
    
    meteor->setTotalParticles(130);
    meteor->setLife(5.0f);
    
    this->addChild(meteor);
    
    
    //旋涡
    auto spiral = ParticleSpiral::create();
    spiral->setTexture(Director::getInstance()->getTextureCache()->addImage("fire.png"));
    spiral->setPosition(Vec2( 450, 40));
    
    spiral->setTotalParticles(130);
    spiral->setLife(5.0f);
    
    this->addChild(spiral);
   
    //爆炸
    auto explosion = ParticleExplosion::create();
    explosion->setTexture(Director::getInstance()->getTextureCache()->addImage("fire.png"));
    explosion->setPosition(Vec2( 50, 440));
    
    explosion->setTotalParticles(130);
    explosion->setLife(5.0f);
    
    this->addChild(explosion);
    
    
    //烟雾
    auto smoke = ParticleSmoke::create();
    smoke->setTexture(Director::getInstance()->getTextureCache()->addImage("fire.png"));
    smoke->setPosition(Vec2( 450, 640));
    
    smoke->setTotalParticles(130);
    smoke->setLife(5.0f);
    
    this->addChild(smoke);
    
    //雪
    auto snow = ParticleSnow::create();
    snow->setTexture(Director::getInstance()->getTextureCache()->addImage("fire.png"));
    snow->setPosition(Vec2( 450, 840));
    
    snow->setTotalParticles(130);
    snow->setLife(5.0f);
    
    this->addChild(snow);

    //雨
    auto rain = ParticleRain::create();
    rain->setTexture(Director::getInstance()->getTextureCache()->addImage("fire.png"));
    rain->setPosition(Vec2( 450, 940));
    
    rain->setTotalParticles(130);
    rain->setLife(5.0f);
    
    this->addChild(rain);
    
    
    
}

效果图:

Cocos2d-x3.1 粒子效果演示样例[通俗易懂]

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/116622.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Mac上安装Mysql配置文件的添加及修改配置文件

    Mac上安装Mysql配置文件的添加及修改配置文件安装Mysql默认安装在/usr/local目录下,这个目录可以通过command+shift+G进入:进入后选择mysql安装文件夹。配置文件Mac上Mysql默认没有配置文件,需要自己添加,可以support-file文件目录下的my-default.cnf复制一份到桌面上,可以把文件中的内容全部替换为一下内容#ExampleMySQLconfigfileforsmall

    2022年6月2日
    744
  • 【Ubuntu安装 Nginx】「建议收藏」

    【Ubuntu安装 Nginx】「建议收藏」ubuntu安装nginx目前支持两种安装方式,一种是apt-get的方式,另一种是根据包安装的方式为方便我统一使用root用户一、apt-get安装nginx切换至root用户sudosurootapt-getinstallnginx如果安装时遇到这种情况,就输入sudoaptupdate在重新输入安装命令即可。查看nginx是否安装成功nginx-v启动nginxservicenginxstart启动后,在网页重输入ip地址,即可看到nginx的欢

    2022年9月19日
    0
  • NTP时间服务器

    1.NTP简介NTP(NetworkTimeProtocol网络时间协议)是一个用于同步计算机时钟的网络协议。它可以使计算机与其他服务器或时钟源进行时间同步,进行高精度的时间校正。简而言之,NTP就是使一台或多台服务器(客户端)与时间服务器(服务端)之间进行时间同步(即客户端与服务端的时间同步),以保证时间的统一性2.NTP服务器架设   上面提到客户端与服务端的时间

    2022年4月6日
    80
  • java中打印数组的方法_Java数组方法–如何在Java中打印数组

    java中打印数组的方法_Java数组方法–如何在Java中打印数组java中打印数组的方法Anarrayisadatastructureusedtostoredataofthesametype.Arraysstoretheirelementsincontiguousmemorylocations.数组是用于存储相同类型数据的数据结构。数组将其元素存储在连续的内存位置中。InJava,arraysareo…

    2022年6月3日
    31
  • 微软历史最高市值是多少?

    微软历史最高市值是多少?

    2021年12月10日
    168
  • Kafka 集群 Golang 应用实例

    Kafka 集群 Golang 应用实例

    2021年6月30日
    97

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号