火花
https://scrapbox.io/files/64cf9352460d43001cf2b0f3.png
code:火花.cpp
# include <Siv3D.hpp>
class SparkParticle {
public:
ParticleSystem2D particleSystem;
ParticleSystem2DParameters parameters;
ArcEmitter2D arcEmitter;
SparkParticle() {
if (not TextureAsset::IsRegistered(U"particle"))
{
TextureAsset::Register(U"particle", U"example/particle.png");
}
parameters.rate = 50;
parameters.startLifeTime = 0.5;
arcEmitter.direction = 80;
arcEmitter.angle = 20;
parameters.startSpeed = 300;
parameters.startColor = Palette::Orange;
particleSystem.setEmitter(arcEmitter);
particleSystem.setTexture(TextureAsset(U"particle"));
particleSystem.setParameters(parameters);
particleSystem.prewarm();
}
//位置を設定
void setPosition(const Vec2& pos) {
particleSystem.setPosition(pos);
}
//角度を設定
void setDirection(double direction) {
if (arcEmitter.direction != direction) {
arcEmitter.direction = direction;
particleSystem.setEmitter(arcEmitter);
}
}
//量を設定
void setRate(double rate) {
parameters.rate = rate;
}
//速さを設定
void setSpeed(double speed) {
parameters.startSpeed = speed;
}
//色を設定
void setColor(const ColorF& color) {
parameters.startColor = color;
}
//更新(毎フレーム呼び出す)
void update() {
particleSystem.setParameters(parameters);
particleSystem.update();
}
//描画
void draw()const {
particleSystem.draw();
}
};
void Main()
{
SparkParticle spark;
while (System::Update())
{
Circle{ Cursor::Pos().x,300,50 }.draw(Palette::Skyblue);
Rect{ 0,350,800,250 }.draw(Palette::Gray);
spark.setDirection(Cursor::Delta().x < 0 ? 80 : -80);
spark.setPosition({ Cursor::Pos().x,350 });
spark.setRate(Abs(Cursor::Delta().x) * 50);
spark.update();
spark.draw();
}
}