Table of Contents
粒子编辑器的使用
下载地址
使用方法
属性讲解
cocos2dx中加载使用plist文件
Home Database Mysql Tutorial 使用 Cocos2d

使用 Cocos2d

Jun 07, 2016 pm 03:32 PM
http use

http://www.tairan.com/archives/5496#2 Cocos2d-x引擎提供了强大的粒子系统,它在模仿自然现象、物理现象及空间扭曲上具备得天独厚的优势,为我们实现一些真实自然而又带有随机性的特效(如爆炸、烟花、水流)提供了方便。尽管如此,它众多的粒子属性还是着

http://www.tairan.com/archives/5496#2

Cocos2d-x引擎提供了强大的粒子系统,它在模仿自然现象、物理现象及空间扭曲上具备得天独厚的优势,为我们实现一些真实自然而又带有随机性的特效(如爆炸、烟花、水流)提供了方便。尽管如此,它众多的粒子属性还是着实让人头疼。因为如果要想自己编码写出炫丽的粒子效果,这里有太多的属性需要手动设置和调节。不管是对新手还是资深的老油条程序员来说,都存在不同程度的不便性。

效果

所以,本文将结合 “天天爱消除” 游戏场景中的粒子特效,讲解如何使用粒子编辑器编辑实现飘飘扬扬往下飞落的的粒子效果。效果如下:

使用 Cocos2d

使用 Cocos2d

粒子编辑器的使用

现在网络中普遍使用的是 Particle Designer编辑器,不过它只支持在Mac系统下使用。对于像我这样的穷屌丝来说,怎么用的起!所以本文将介绍另一个粒子编辑器particle-editor的使用方法,它的功能同样强大,而且还支持在windows系统下使用。两种编辑器的用法大同小异,都可以把编辑出的粒子效果直接导出为plist文件。

下载地址

particle-editor的下载地址:

https://code.google.com/p/cocos2d-windows-particle-editor/downloads/detail?name=ParticleEditor%20V2.0.7z&can=2&q=

使用方法

particle-editor编辑器无需安装,下载解压后即可使用,它的编辑界面如下:

使用 Cocos2d

菜单栏的 Samples 下为用户提供了一些常用的粒子特效,如烟花、火、流星等,你可根据需要创建不同的粒子群。

属性讲解

编辑器的属性:

  • IsBackgroundMove 编辑器背景图片是否滚动,如果你觉得它动来动去的很烦人,你可以把它设置为False

  • IsSaveTextureImageData 是否把图片数据编码到文件里导出,这里我建议把它设置为False

  • Scale 编辑器画布缩放比例大小

编辑器的属性只影响编辑器内的预览效果,不对保存的.plist文件产生影响。而下面的所有属性都对应Cocos2dx中粒子系统的各属性,会直接影响生成的.plist文件。

主要属性:

  • Duration 发射器生存时间,即它可以发射粒子的时间,注意这个时间和粒子生存时间不同。单位秒,-1表示永远;粒子发射结束后可点击工具栏的播放按钮使用 Cocos2d再次发射

  • EmissionRate 每秒喷发的粒子数目

  • IsAutoRemoveOnFinish 粒子结束时是否自动删除

  • Mode 喷发器模式,有重力模式(Gravity)和半径模式(Radius,也叫放射模式)两种

  • TotalParticles 场景中存在的最大粒子数目,往往与EmissionRate配合起来使用

使用 Cocos2d

半径模式:半径模式可以使粒子以圆圈方式旋转,它也可以创造螺旋效果让粒子急速前进或后退。下列各属性只在半径模式下起作用。

  • EndRadius 结束半径

  • EndRadiusVar 结束半径变化范围,即结束半径值的范围在 (EndRadius – EndRadiusVar) 和 (EndRadius + EndRadiusVar )之间,下面类似。

  • RotatePerSecond 粒子每秒围绕起始点的旋转角度

  • RotatePerSecondVar 粒子每秒围绕起始点的旋转角度变化范围

  • StartRadius 初始半径

  • StartRadius 初始半径变化范围

重力模式:顾名思义,重力模式模拟重力,可让粒子围绕一个中心点移近或移远,它的优点是非常动态,而且移动有规则。下列各属性只在重力模式下起作用。

  • GravityX 重力X

  • GravityY 重力Y

  • RadiaAccel 粒子径向加速度,即平行于重力方向的加速度

  • RadiaAccelVar 粒子径向加速度变化范围

  • Speed 速度

  • SpeedVar 速度变化范围

  • TangentialAccel 粒子切向加速度,即垂直于重力方向的加速度

  • TangentialAccelVar 粒子切向加速度变化范围

生命属性:

  • Life 粒子生命,即粒子的生存时间 

  • LifeVar 粒子生命变化范围

大小属性:

  • EndSize 粒子结束时的大小,-1表示和初始大小一致

  • EndSize 粒子结束大小的变化范围

  • StartSize 粒子的初始大小

  • StartSize 粒子初始大小的变化范围

角度属性:

  • Angle 粒子角度

  • AngleVar 粒子角度变化范围

颜色属性:

  • EndColor 粒子结束颜色

  • EndColorVar 粒子结束颜色变化范围

  • StartColor 粒子初始颜色

  • StartColorVar 粒子初始颜色变化范围

使用 Cocos2d

如果你不想编辑出五颜六色的粒子效果,那应该把EndColorVar,StartColorVar尽量设置为(0, 0, 0, 0)。

位置属性:

  • PositionType 粒子位置类型,有自由模式(Free)、相对模式(Relative)和打组模式(Grouped)三种

  • PosVarX 发射器位置的横向变化范围,烟花出现在位置相对中心位置的像素偏移 

  • PosVarY 发射器位置的纵向变化范围

  • SourcePositionX 发射器原始X坐标位置

  • SourcePositionY 发射器原始Y坐标位置

Free自由模式,相对于屏幕自由,不会随粒子节点移动而移动(可产生火焰、蒸汽等效果);Relative相对模式,相对于被绑定的Node静止,粒子发射器会随Node移动而移动,可用于制作移动角色身上的特效等等;Grouped打组模式是相对于发射点的,粒子随发射器移动而移动。

自旋属性:

  • EndSpin 粒子结束自旋角度

  • EndSpinVar 粒子结束自旋角度变化范围

  • StartSpin 粒子开始自旋角度

  • StartSpinVar 粒子开始自旋角度变化范围

纹理渲染属性:

  • DestBlendFunc 目的纹理的混合模式

  • SrcBlendFunc 源纹理的混合模式

  • TextureImageData 纹理数据

  • TexturePath 纹理路径,目前只可为Debug.win32目录下文件名

使用 Cocos2d

Cocos2dx使用OpenGL混合原理对图形进行渲染绘制。混合就是指把两种颜色混在一起,具体一点就是把某一像素位置原来的颜色和将要画上去的颜色,通过某种方式混在一起,从而实现特殊的效果。它是一种常用的技巧,通常可以用来实现半透明,你也可以通过不同的设置得到不同的混合结果,产生一些有趣或者奇怪的图象。

使用 Cocos2d使用 Cocos2d

这里的源纹理和目标纹理跟绘制的顺序有关,先绘制的纹理是目标纹理,后绘制的纹理理所应当的就成为了源纹理。下面具体来看看混合模式的属性值。

DestBlendFunc和SrcBlendFunc的常用值为以下几种情况:

  • GL_ZERO: 表示使用0.0作为因子,实际上相当于不使用这种颜色参与混合运算。

  • GL_ONE: 表示使用1.0作为因子,实际上相当于完全的使用了这种颜色参与混合运算。

  • GL_SRC_ALPHA:表示使用源颜色的alpha值来作为因子。

  • GL_DST_ALPHA:表示使用目标颜色的alpha值来作为因子。

  • GL_ONE_MINUS_SRC_ALPHA:表示用1.0减去源颜色的alpha值来作为因子。

  • GL_ONE_MINUS_DST_ALPHA:表示用1.0减去目标颜色的alpha值来作为因子。

最常用的组合模式有两种:GL_ONE和GL_ONE_MINUS_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA和GL_SRC_ALPHA。

介绍完编辑器的各属性项以后,我们就可以根据需要编辑出不同效果的粒子效果了。下图是类似天天爱消除游戏中的“雪花”粒子特效。

使用 Cocos2d

资源图片使用 Cocos2d ,在使用粒子编辑器编辑粒子时,应放在粒子编辑器的ParticleEditor目录下;导出plist文件时,应把资源图片和plist文件放一起。该资源下载地址:https://github.com/renshan/btnTest/tree/master/snow-plist

注意:这里目的纹理的混合模式设置为GL_ONE,源纹理的混合模式设置为GL_ONE_MINUS_SRC_ALPHA。

cocos2dx中加载使用plist文件

只要编辑出粒子效果,那在cocos2d-x引擎中加载plist文件就非常简单了。使用以下代码来读取粒子效果:

<span><span>//贴背景图片</span><span>Sprite</span><span>*</span><span> pSprite </span><span>=</span><span>Sprite</span><span>::</span><span>create</span><span>(</span><span>"IMG1.jpg"</span><span>);</span><span>
    pSprite</span><span>-></span><span>setPosition</span><span>(</span><span>Point</span><span>(-</span><span>20</span><span>,</span><span>0</span><span>));</span><span>
    pSprite</span><span>-></span><span>setAnchorPoint</span><span>(</span><span>Point</span><span>(</span><span>0</span><span>,</span><span>0</span><span>));</span><span>this</span><span>-></span><span>addChild</span><span>(</span><span>pSprite</span><span>,</span><span>0</span><span>);</span><span>//读取粒子效果</span><span>ParticleSystem</span><span>*</span><span> m_emitter1 </span><span>=</span><span>ParticleSystemQuad</span><span>::</span><span>create</span><span>(</span><span>"snow.plist"</span><span>);</span><span>
    m_emitter1</span><span>-></span><span>retain</span><span>();</span><span>ParticleBatchNode</span><span>*</span><span>batch </span><span>=</span><span>ParticleBatchNode</span><span>::</span><span>createWithTexture</span><span>(</span><span>m_emitter1</span><span>-></span><span>getTexture</span><span>());</span><span>
    batch</span><span>-></span><span>addChild</span><span>(</span><span>m_emitter1</span><span>);</span><span>
    addChild</span><span>(</span><span>batch</span><span>,</span><span>10</span><span>);</span><span>
    m_emitter1</span><span>-></span><span>release</span><span>();</span><span>//或读取粒子效果</span><span>//ParticleSystem* m_emitter1 = ParticleSystemQuad::create("snow.plist");</span><span>//addChild(m_emitter1);</span></span>
Copy after login

这里ParticleBatchNode可以引用且只可以引用1个texture(一个图片文件,一个texture图集),增加到SpriteBatchNode中的ParticleSystem都是在OpenGL ES调用绘图函数时绘制的。

如果ParticleSystem没有增加到ParticleBatchNode中,OpenGL ES会调用每个粒子系统的绘图函数,这样做效率会比较低。

好了,基本上就这些,比想象中简单多了吧,点此可下载工程。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What software is crystaldiskmark? -How to use crystaldiskmark? What software is crystaldiskmark? -How to use crystaldiskmark? Mar 18, 2024 pm 02:58 PM

CrystalDiskMark is a small HDD benchmark tool for hard drives that quickly measures sequential and random read/write speeds. Next, let the editor introduce CrystalDiskMark to you and how to use crystaldiskmark~ 1. Introduction to CrystalDiskMark CrystalDiskMark is a widely used disk performance testing tool used to evaluate the read and write speed and performance of mechanical hard drives and solid-state drives (SSD). Random I/O performance. It is a free Windows application and provides a user-friendly interface and various test modes to evaluate different aspects of hard drive performance and is widely used in hardware reviews

How to download foobar2000? -How to use foobar2000 How to download foobar2000? -How to use foobar2000 Mar 18, 2024 am 10:58 AM

foobar2000 is a software that can listen to music resources at any time. It brings you all kinds of music with lossless sound quality. The enhanced version of the music player allows you to get a more comprehensive and comfortable music experience. Its design concept is to play the advanced audio on the computer The device is transplanted to mobile phones to provide a more convenient and efficient music playback experience. The interface design is simple, clear and easy to use. It adopts a minimalist design style without too many decorations and cumbersome operations to get started quickly. It also supports a variety of skins and Theme, personalize settings according to your own preferences, and create an exclusive music player that supports the playback of multiple audio formats. It also supports the audio gain function to adjust the volume according to your own hearing conditions to avoid hearing damage caused by excessive volume. Next, let me help you

How to use Baidu Netdisk app How to use Baidu Netdisk app Mar 27, 2024 pm 06:46 PM

Cloud storage has become an indispensable part of our daily life and work nowadays. As one of the leading cloud storage services in China, Baidu Netdisk has won the favor of a large number of users with its powerful storage functions, efficient transmission speed and convenient operation experience. And whether you want to back up important files, share information, watch videos online, or listen to music, Baidu Cloud Disk can meet your needs. However, many users may not understand the specific use method of Baidu Netdisk app, so this tutorial will introduce in detail how to use Baidu Netdisk app. Users who are still confused can follow this article to learn more. ! How to use Baidu Cloud Network Disk: 1. Installation First, when downloading and installing Baidu Cloud software, please select the custom installation option.

How to use NetEase Mailbox Master How to use NetEase Mailbox Master Mar 27, 2024 pm 05:32 PM

NetEase Mailbox, as an email address widely used by Chinese netizens, has always won the trust of users with its stable and efficient services. NetEase Mailbox Master is an email software specially created for mobile phone users. It greatly simplifies the process of sending and receiving emails and makes our email processing more convenient. So how to use NetEase Mailbox Master, and what specific functions it has. Below, the editor of this site will give you a detailed introduction, hoping to help you! First, you can search and download the NetEase Mailbox Master app in the mobile app store. Search for "NetEase Mailbox Master" in App Store or Baidu Mobile Assistant, and then follow the prompts to install it. After the download and installation is completed, we open the NetEase email account and log in. The login interface is as shown below

BTCC tutorial: How to bind and use MetaMask wallet on BTCC exchange? BTCC tutorial: How to bind and use MetaMask wallet on BTCC exchange? Apr 26, 2024 am 09:40 AM

MetaMask (also called Little Fox Wallet in Chinese) is a free and well-received encryption wallet software. Currently, BTCC supports binding to the MetaMask wallet. After binding, you can use the MetaMask wallet to quickly log in, store value, buy coins, etc., and you can also get 20 USDT trial bonus for the first time binding. In the BTCCMetaMask wallet tutorial, we will introduce in detail how to register and use MetaMask, and how to bind and use the Little Fox wallet in BTCC. What is MetaMask wallet? With over 30 million users, MetaMask Little Fox Wallet is one of the most popular cryptocurrency wallets today. It is free to use and can be installed on the network as an extension

How to use Xiaoai Speaker How to connect Xiaoai Speaker to mobile phone How to use Xiaoai Speaker How to connect Xiaoai Speaker to mobile phone Feb 22, 2024 pm 05:19 PM

After long pressing the play button of the speaker, connect to wifi in the software and you can use it. Tutorial Applicable Model: Xiaomi 12 System: EMUI11.0 Version: Xiaoai Classmate 2.4.21 Analysis 1 First find the play button of the speaker, and press and hold to enter the network distribution mode. 2 Log in to your Xiaomi account in the Xiaoai Speaker software on your phone and click to add a new Xiaoai Speaker. 3. After entering the name and password of the wifi, you can call Xiao Ai to use it. Supplement: What functions does Xiaoai Speaker have? 1 Xiaoai Speaker has system functions, social functions, entertainment functions, knowledge functions, life functions, smart home, and training plans. Summary/Notes: The Xiao Ai App must be installed on your mobile phone in advance for easy connection and use.

Teach you how to use the new advanced features of iOS 17.4 'Stolen Device Protection' Teach you how to use the new advanced features of iOS 17.4 'Stolen Device Protection' Mar 10, 2024 pm 04:34 PM

Apple rolled out the iOS 17.4 update on Tuesday, bringing a slew of new features and fixes to iPhones. The update includes new emojis, and EU users will also be able to download them from other app stores. In addition, the update also strengthens the control of iPhone security and introduces more "Stolen Device Protection" setting options to provide users with more choices and protection. "iOS17.3 introduces the "Stolen Device Protection" function for the first time, adding extra security to users' sensitive information. When the user is away from home and other familiar places, this function requires the user to enter biometric information for the first time, and after one hour You must enter information again to access and change certain data, such as changing your Apple ID password or turning off stolen device protection.

How to use Thunder to download magnet links How to use Thunder to download magnet links Feb 25, 2024 pm 12:51 PM

With the rapid development of network technology, our lives have also been greatly facilitated, one of which is the ability to download and share various resources through the network. In the process of downloading resources, magnet links have become a very common and convenient download method. So, how to use Thunder magnet links? Below, I will give you a detailed introduction. Xunlei is a very popular download tool that supports a variety of download methods, including magnet links. A magnet link can be understood as a download address through which we can obtain relevant information about resources.

See all articles