Change the particle example to move the particle emitter to the mouse
This commit is contained in:
parent
2f1922952c
commit
32f83fa67b
|
@ -13,6 +13,7 @@
|
||||||
#include <SFML/System/Vector3.hpp>
|
#include <SFML/System/Vector3.hpp>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <ratio>
|
||||||
#include <simpleengine/game.h>
|
#include <simpleengine/game.h>
|
||||||
#include <simpleengine/event.h>
|
#include <simpleengine/event.h>
|
||||||
#include <simpleengine/entity.h>
|
#include <simpleengine/entity.h>
|
||||||
|
@ -46,14 +47,16 @@ private:
|
||||||
Super::ParticlePropertyVector particle_properties;
|
Super::ParticlePropertyVector particle_properties;
|
||||||
Super::EmitterPropertyVector emitter_properties;
|
Super::EmitterPropertyVector emitter_properties;
|
||||||
public:
|
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.loadFromFile("particle.png"); // The particle I tested with was 5x5 pixels
|
||||||
texture.setSmooth(true);
|
texture.setSmooth(true);
|
||||||
|
|
||||||
particle_properties.emplace_back(std::make_unique<se::particle::RandomVelocityParticleProperty>(se::Range2f(-1.5f, 1.5f, -1.5f, 1.5f)));
|
particle_properties.emplace_back(std::make_unique<se::particle::RandomVelocityParticleProperty>(se::Range2f(-1.5f, 1.5f, -1.5f, 1.5f)));
|
||||||
|
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
particle_properties.emplace_back(std::make_unique<se::particle::RandomLifetimeParticleProperty>(2'500ms, 5'500ms));
|
particle_properties.emplace_back(std::make_unique<se::particle::RandomLifetimeParticleProperty>(1'500ms, 2'500ms));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update(const float& delta_time) override {
|
void Update(const float& delta_time) override {
|
||||||
|
@ -63,11 +66,26 @@ public:
|
||||||
void Render(sf::RenderTarget* target) override {
|
void Render(sf::RenderTarget* target) override {
|
||||||
Super::Render(target);
|
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[]) {
|
int main(int argc, char *argv[]) {
|
||||||
simpleengine::Game game(700, 700, "SimpleEngine - Particles Example");
|
simpleengine::Game game(700, 700, "SimpleEngine - Particles Example");
|
||||||
game.AddEvent(new ParticleEmitter());
|
|
||||||
|
ParticleEmitter* emitter = new ParticleEmitter();
|
||||||
|
game.AddEventCallback<sf::Event::EventType::MouseMoved>(std::function([&](sf::Event::MouseMoveEvent event) {
|
||||||
|
OnMouseMove(emitter, event);
|
||||||
|
}));
|
||||||
|
|
||||||
|
game.AddEvent(emitter);
|
||||||
|
|
||||||
return game.Run();
|
return game.Run();
|
||||||
}
|
}
|
Loading…
Reference in New Issue