diff --git a/examples/particles/src/main.cpp b/examples/particles/src/main.cpp index a47c80c..4343fdc 100644 --- a/examples/particles/src/main.cpp +++ b/examples/particles/src/main.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -46,14 +47,16 @@ private: Super::ParticlePropertyVector particle_properties; Super::EmitterPropertyVector emitter_properties; public: - ParticleEmitter() : Super(texture, sf::Vector2f(350, 350), .5f, 10, 900, se::Range2f(-50, 50, -50, 50), se::particle::ParticleAttributes{2000, sf::Vector2f(.1f, .1f), 5, sf::Vector2f(2, 2)}, particle_properties, emitter_properties) { + ParticleEmitter() : Super(texture, sf::Vector2f(350, 350), .5f, 5, 900, se::Range2f(-25, 25, -25, 25), + se::particle::ParticleAttributes{std::chrono::milliseconds(500), sf::Vector2f(.1f, .1f), 5, + sf::Vector2f(2, 2)}, particle_properties, emitter_properties) { texture.loadFromFile("particle.png"); // The particle I tested with was 5x5 pixels texture.setSmooth(true); particle_properties.emplace_back(std::make_unique(se::Range2f(-1.5f, 1.5f, -1.5f, 1.5f))); using namespace std::chrono_literals; - particle_properties.emplace_back(std::make_unique(2'500ms, 5'500ms)); + particle_properties.emplace_back(std::make_unique(1'500ms, 2'500ms)); } void Update(const float& delta_time) override { @@ -63,11 +66,26 @@ public: void Render(sf::RenderTarget* target) override { Super::Render(target); } + + void SetPosition(int x, int y) { + position.x = x; + position.y = y; + } }; +void OnMouseMove(ParticleEmitter* emitter, sf::Event::MouseMoveEvent event) { + emitter->SetPosition(event.x, event.y); +} + int main(int argc, char *argv[]) { simpleengine::Game game(700, 700, "SimpleEngine - Particles Example"); - game.AddEvent(new ParticleEmitter()); + + ParticleEmitter* emitter = new ParticleEmitter(); + game.AddEventCallback(std::function([&](sf::Event::MouseMoveEvent event) { + OnMouseMove(emitter, event); + })); + + game.AddEvent(emitter); return game.Run(); } \ No newline at end of file