Effekseer For Cocos2d-x
摘要
Effekseer是一個可以輕鬆地創建美麗的粒子效果的工具。本程式庫將能夠在Cocos2d-X內播放由Effekseer創建而成的粒子效果。 本文檔會介紹如何在Cocos2d-x內使用本程式庫。 程式庫是由複數源代碼組成,通過新增本源代碼便可為Cocos2d-x進行安裝。
對應環境如下
Windows | OK |
Mac OS X | OK |
Linux | Unknown |
iOS | OK |
Android | OK |
WindowsPhone | Unknown |

如何安裝
Players/Cocos2d-x_v3的文件夾內會包含以下文件。
- Effekseer.cpp
- Effekseer.h
- EffekseerNative.cpp
- EffekseerNative.h
- EffekseerRendererNative.cpp
- EffekseerRendererNative.h
將這些文件複製到的Cocos2d-x的文件夾內,再設定成編譯對象。
如何使用
在Samples/文件夾內會有在Cocos2d-x內播放Effekseer粒子效果的樣本。本文件只會作出簡單的使用方法。詳細請參閱樣本。
樣本是不包含在此程式庫內,請將各樣本複製到Classes/Effekseer文件夾內使用。 為方便得知文件存放的位置、會有一個名為copyEffekseerFiles.txt的文件作為標籤而作識別。
有關可播放的文件
您只可以播放由Effekseer保存而成的文件。由Effekseer保存的文件中包含圖像的相對路徑。因此,請留意各檔案的存放位置。
基本播放
由Effekseer保存而成的文件可在cocos2d-x內播放。 欲了解更多資訊,請查看存儲在Samples/Simple/內的源代碼。
包括Effekseer.h。
#include "Effekseer/Effekseer.h"
在cocos2d::Layer的衍生類別內加入成員變量efk::EffectManager*。
class HelloWorld : public cocos2d::Layer { efk::EffectManager* manager = nullptr; ...
建立執行個體efk::EffectManager*。
manager = efk::EffectManager::create(Director::getInstance()->getVisibleSize());
讀取粒子效果文件。
auto effect = efk::Effect::create("Laser01.efk");
建立發射極,並通過將參數添加到階層。
auto emitter = efk::EffectEmitter::create(manager); emitter->setEffect(effect); emitter->setPlayOnEnter(true); emitter->setPosition(Vec2(300, 300)); emitter->setScale(20); this->addChild(emitter, 0); effect->release();
更新畫面。
manager->update();
衍生visit,使可添加的繪製效果的處理。
void HelloWorld::visit( cocos2d::Renderer *renderer, const cocos2d::Mat4& parentTransform, uint32_t parentFlags) { manager->begin(renderer, _globalZOrder); cocos2d::Layer::visit(renderer, parentTransform, parentFlags); manager->end(renderer, _globalZOrder); }
刪除執行個體。
HelloWorld::~HelloWorld() { manager->release(); }
授權
如使用Effekseer,你需要添加下面的措辭。(例如在幫助內)
The MIT License (MIT) Copyright (c) 2011 Effekseer Project Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. DirectX Tool Kit https://directxtk.codeplex.com/ Microsoft Public License (Ms-PL)
更新
1.40 (18/09/12) More functions added. Speed up with Android and iOS. Supported 3D.
1.30 (17/11/03) 發布。