出現エフェクト
https://scrapbox.io/files/64db81ee3633fe001cb45575.png
code:出現エフェクト.cpp
# include <Siv3D.hpp>
struct AppearedEffect : IEffect
{
ParticleSystem2D particleSystem;
ParticleSystem2DParameters parameters;
double rate;
// このコンストラクタ引数が、Effect::add<RingEffect>() の引数になる
explicit AppearedEffect(const Polygon& polygon, const Vec2& pos, const ColorF& color = HSV{ 180,0.8,1 }, double size = 100, double rate = 500)
:rate{ rate }
{
TextureAsset::Register(U"particle", U"example/particle.png");
PolygonEmitter2D emitter{ polygon };
parameters.startSize = size;
parameters.startColor = color;
parameters.rate = 0;
particleSystem.setEmitter(emitter);
particleSystem.setTexture(TextureAsset(U"particle"));
particleSystem.setParameters(parameters);
particleSystem.setPosition(pos);
particleSystem.prewarm();
}
bool update(double t) override
{
if (2.0 < t)parameters.rate = 0;
else parameters.rate = t * rate;
particleSystem.setParameters(parameters);
particleSystem.update();
particleSystem.draw();
return (t < 3.0);
}
};
Polygon CreatePolygon()
{
return Image{ U"example/siv3d-kun.png" }
.alphaToPolygonCentered().simplified(1);
}
void Main()
{
Effect effect;
Polygon polygon = CreatePolygon();
Vec2 position = Scene::Center();
Texture siv3dkun{ U"example/siv3d-kun.png" };
Timer timer{ 2s };
bool appearedFlg = false;
while (System::Update())
{
if (MouseL.down())
{
effect.add<AppearedEffect>(polygon, position);
appearedFlg ^= true;
timer.restart();
}
if (timer.isRunning()^ appearedFlg) {
siv3dkun.drawAt(position);
}
effect.update();
}
}