axmol/tests/cpp-tests/Source/EffekseerTest/EffekseerTest.cpp

219 lines
5.7 KiB
C++
Raw Normal View History

2022-11-01 20:02:56 +08:00
/****************************************************************************
Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
2022-11-01 20:02:56 +08:00
https://axmolengine.github.io/
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.
****************************************************************************/
2022-11-01 19:50:43 +08:00
#include "EffekseerTest.h"
#include <iostream>
#include <fstream>
#include <string.h>
USING_NS_AX;
//------------------------------------------------------------------
//
// SpineTestScene
//
//------------------------------------------------------------------
EffekseerTests::EffekseerTests()
{
auto fu = FileUtils::getInstance();
_searchPaths = fu->getSearchPaths();
fu->addSearchPath("Effekseer", true);
ADD_TEST_CASE(EffekseerTest);
}
EffekseerTests::~EffekseerTests()
{
FileUtils::getInstance()->setSearchPaths(_searchPaths);
}
EffekseerTest::EffekseerTest() : _title("EffekseerTest") {}
EffekseerTest::~EffekseerTest() {
/**
You will destroy the manager on exit.
*/
manager->release();
}
std::string EffekseerTest::title() const
{
return _title;
}
bool EffekseerTest::init()
{
if (!TestCase::init())
return false;
auto rsize = _director->getGLView()->getDesignResolutionSize();
2022-11-01 19:50:43 +08:00
//auto sprite = Sprite::create("HelloWorld.png");
//sprite->setPosition(Vec2(320, 200));
//this->addChild(sprite, 0);
2022-11-01 19:50:43 +08:00
// for update
this->scheduleUpdate();
/**
efk::EffectManagerのインスタンスを生成します
You create an instance of efk::EffectManager.
efk::EffectManager的實例
efk::EffectManager的实例
*/
manager = efk::EffectManager::create(rsize);
return true;
}
void EffekseerTest::update(float delta)
{
// Effect1
if (count % 300 == 0)
{
/**
You read an effect file with specifying scale.
*/
auto effect = efk::Effect::create("Laser01.efk", 13.0f);
if (effect != nullptr)
{
/**
You generate an emitter, set parameters and add it to the layer.
*/
auto emitter = efk::EffectEmitter::create(manager);
emitter->setEffect(effect);
emitter->setPlayOnEnter(true);
2022-11-01 19:50:43 +08:00
emitter->setRotation3D(cocos2d::Vec3(0, 90, 0));
emitter->setPosition(Vec2(320, 150));
2022-11-01 19:50:43 +08:00
// emitter->setScale(13);
this->addChild(emitter, 0);
// No need (because it uses autorelease after 1.41)
//effect->release();
}
}
// Effect2
if (count % 300 == 120)
{
/**
You read an effect file.
*/
auto effect = efk::Effect::create("Homing_Laser01.efk");
if (effect != nullptr)
{
/**
You generate an emitter, set parameters and add it to the layer.
*/
auto emitter = efk::EffectEmitter::create(manager);
emitter->setEffect(effect);
emitter->setPlayOnEnter(true);
emitter->setPosition(Vec2(320, 150));
emitter->setScale(4);
this->addChild(emitter, 0);
/**
Some parameters are required to set after addChild
AddChildした後に設定する必要があります
*/
emitter->setTargetPosition(cocos2d::Vec3(320, 480, 0));
// No need (because it uses autorelease after 1.41)
//effect->release();
}
}
/**
You update the manager every frame.
*/
manager->update();
count++;
}
void EffekseerTest::visit(cocos2d::Renderer *renderer, const cocos2d::Mat4& parentTransform, uint32_t parentFlags)
{
/**
visitを継承して
You inherit visit and add a process to actually draw the effect.
visit
visit
*/
manager->begin(renderer, _globalZOrder);
cocos2d::Scene::visit(renderer, parentTransform, parentFlags);
manager->end(renderer, _globalZOrder);
}