Effekseer For Cocos2d-x

Overview

Effekseer is a tool that makes it easy to create beautiful particle effects. This library allows you to play particle effects created with Effekseer on Cocos2d-x. This document describes cooperation between Effekseer and Cocos2d-x. The library consists of multiple source code files, and you can install it by adding the source code file to the project of Cocos2d-x.

The corresponding environment is as follows.

Windows OK
Mac OS X OK
Linux Unknown
iOS OK
Android OK
WindowsPhone Unknown

Important

Cocos2d-x Effekseer branch is required to use it with Cocos2d-x v4 and MacOSX

Cocos2d-x Effekseer branch

Installation method (Version4)

Please copy Players/Cocos2d-x_v4 to the project of Cocos 2d-x.

Add codes int CMakeLists.txt as follows.

add_subdirectory(Cocos2d-x_v4)
target_link_libraries(${APP_NAME} EffekseerForCocos2d-x)

How to use

In Samples/ directory in Cocos2d-x is a sample to play the particle effects of Effekseer. Since this document only explains basic usage, please see the sample for detailed usage.

These samples, for this library is not included, please copy the library of files in each sample of Classes/Effekseer directory. copyEffekseerFiles.txt file exists in the directory to copy to as the marker of the directory to which the library is copied.

About files that can be played

Only files saved by Effekseer's standard output can be played. The saved file contains the relative path from Effekseer's project to the image. For that reason, you need to place the image while keeping the relative path from the file saved in standard output to the image.

Basic playback

Play effects files saved with Effekseer's standard output with Cocos2d-x. For more information, please look at the source code that is stored in the Samples/Simple/.


Include EffekseerForCocos2d-x.h(Version4) or Effekseer.h(Version3).

#if COCOS2D_VERSION >= 0x00040000
#include "EffekseerForCocos2d-x.h"
#else
#include "Effekseer/Effekseer.h"
#endif

Add efk::EffectManager* to the member variable of the class that inherits cocos2d::Scene or cocos2d::Layer.

class HelloWorld : public cocos2d::Scene /* Layer */ {
efk::EffectManager* manager = nullptr;
...

Create an instance of efk::EffectManager*.

manager = efk::EffectManager::create(Director::getInstance()->getVisibleSize());

Load the effect file.

auto effect = efk::Effect::create("Laser01.efk");

Generate the emitter, set the parameters and add it to the scene.

auto emitter = efk::EffectEmitter::create(manager);
emitter->setEffect(effect);
emitter->setPlayOnEnter(true);

emitter->setPosition(Vec2(300, 300));
emitter->setScale(20);
this->addChild(emitter, 0);

// No need (because it uses autorelease after 1.41)
//effect->release();

Update the manager every frame. The effect will be rendered in the posture it was in when the manager was updated.

manager->update();

Inherit visit and add a process to actually draw the effect.

void HelloWorld::visit(
	cocos2d::Renderer *renderer, 
	const cocos2d::Mat4& parentTransform, 
	uint32_t parentFlags)
{
	manager->begin(renderer, _globalZOrder);
	cocos2d::Scene::visit(renderer, parentTransform, parentFlags);
	manager->end(renderer, _globalZOrder);
}

Discard the manager at the end.

HelloWorld::~HelloWorld()
{
	manager->release();
}

3D

Please read a sample in Samples/3D/.

You need to add a camera in cocos2d-x's Scene

auto s = Director::getInstance()->getWinSize();
camera = Camera::createPerspective(60, (GLfloat)s.width / s.height, 1, 1000);
camera->setPosition3D(Vec3(100, 100, 100));
camera->lookAt(Vec3(0, 0, 0), Vec3(0, 1, 0));
camera->setCameraFlag(cocos2d::CameraFlag::USER1);

In addition to update the manager, you need to set camera parameters into the manager.

manager->update();
manager->setCameraMatrix(camera->getViewMatrix());
manager->setProjectionMatrix(camera->getProjectionMatrix());

Network

You can edit the playing effect in an application (game etc.) via the network from the outside when application is running.

Create an instance of server and execute makeNetworkServerEnabled with the port to be connected from Effekseer as the argument of this function.

networkSever = efk::NetworkServer::create();
networkSever->makeNetworkServerEnabled(60000);

In addition to update the manager, you need to update the server. Then you can edit the effect from Effekseer. In order to edit the effect from another computer, it is necessary to open the port with the setting of the firewall.

manager->update();
networkSever->update();

License

When using Effekseer, you need to add the following text to help etc.

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.

Change log

1.52m or later

Release notes

1.52k (20/08/16)

Fixed a bug where a distortion is not supported on Android.

Changed to show a warning when non-squared images are loaded.

Updated Effekseer to 1.52k

1.52j (20/08/02)

Updated Effekseer to 1.52j

1.52i (20/07/30)

Updated Effekseer to 1.52i

1.52h (20/07/09)

Updated Effekseer to 1.52h

Fixed a bug that alpha channel is wrong

1.52g (20/06/09)

Updated Effekseer to 1.52g

1.52b (20/05/02)

Fixed a bug where particles are not shown with Line of SpawnMethod

1.52a (20/04/28)

Fixed a bug that a behavior of rotated billboard is something wrong when an angle is about 90 degree

1.52 (20/04/25)

Various bug fixes, including crashes.

1.50 (20/03/18)

Supported cocos2d-x v4

Fixed many bugs

1.43c (19/09/16)

fixed a bug which causes crash if PlayOnEnter is false, and call play after next frame

fixed a bug that parameters are not applied which are assigned before playing

1.43b (19/08/03)

Fixed OpenGL blend bug

Fixed Samples

1.43 (19/03/02)

Added network functions

1.42 (19/02/08)

Added image caching function

Added documentation

Fixed bug that the behavior of the ribbon and track generated with the 0th frame is wrong

Fixed bug that SSE buffer overrun crashes

Fixed bug that crashes on Android when specifying easing of color

1.41 (18/11/10)

Fixed a bug causes crach when setRemoveOnStop is used. Fixed memory leak in samples.

This release makes Effect and EffectEmitter released automatically. So you need to edit codes about release

1.40 (18/09/12) More functions added. Speed up with Android and iOS. Supported 3D.

1.30 (17/11/03) released.