particles start final size
This commit is contained in:
parent
6973e1639a
commit
e3e6770957
|
@ -20,7 +20,8 @@ ParticleSystem
|
|||
particle-velocity: 32
|
||||
particle-velocity-angle: 0
|
||||
particle-acceleration: 0
|
||||
particle-size: 32 32
|
||||
particle-start-size: 4 4
|
||||
particle-final-size: 48 48
|
||||
particle-colors: #00ff00ff #ff0000ff #0000ffff #00ff00ff #00ff0000
|
||||
particle-colors-stops: 3 6 9 12
|
||||
particle-texture: circle2.png
|
||||
|
|
|
@ -24,14 +24,14 @@
|
|||
#include "graphics.h"
|
||||
#include <framework/core/clock.h>
|
||||
|
||||
Particle::Particle(const Point& pos, const Size& size, const PointF& velocity, const PointF& acceleration, float duration, float ignorePhysicsAfter, const std::vector<Color>& colors, const std::vector<float>& colorsStops, TexturePtr texture)
|
||||
Particle::Particle(const Point& pos, const Size& startSize, const Size& finalSize, const PointF& velocity, const PointF& acceleration, float duration, float ignorePhysicsAfter, const std::vector<Color>& colors, const std::vector<float>& colorsStops, TexturePtr texture)
|
||||
{
|
||||
m_colors = colors;
|
||||
m_colorsStops = colorsStops;
|
||||
|
||||
m_rect = Rect(pos, size);
|
||||
m_position = PointF(pos.x, pos.y);
|
||||
m_size = size;
|
||||
m_startSize = startSize;
|
||||
m_finalSize = finalSize;
|
||||
m_velocity = velocity;
|
||||
m_acceleration = acceleration;
|
||||
|
||||
|
@ -65,6 +65,9 @@ void Particle::update(double elapsedTime)
|
|||
|
||||
updateColor();
|
||||
|
||||
// update size
|
||||
m_size = m_startSize + (m_finalSize - m_startSize) / m_duration * m_elapsedTime;
|
||||
|
||||
// update position
|
||||
if(m_ignorePhysicsAfter < 0 || m_elapsedTime < m_ignorePhysicsAfter ) {
|
||||
// update position
|
||||
|
@ -74,10 +77,11 @@ void Particle::update(double elapsedTime)
|
|||
|
||||
// update acceleration
|
||||
m_velocity += m_acceleration * elapsedTime;
|
||||
|
||||
m_rect.moveTo((int)m_position.x - m_size.width() / 2, (int)m_position.y - m_size.height() / 2);
|
||||
}
|
||||
|
||||
m_rect.moveTo((int)m_position.x - m_size.width() / 2, (int)m_position.y - m_size.height() / 2);
|
||||
m_rect.resize(m_size);
|
||||
|
||||
m_elapsedTime += elapsedTime;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
class Particle {
|
||||
public:
|
||||
Particle(const Point& pos, const Size& size, const PointF& velocity, const PointF& acceleration, float duration, float ignorePhysicsAfter, const std::vector<Color>& colors, const std::vector<float>& colorsStops, TexturePtr texture = nullptr);
|
||||
Particle(const Point& pos, const Size& startSize, const Size& finalSize, const PointF& velocity, const PointF& acceleration, float duration, float ignorePhysicsAfter, const std::vector<Color>& colors, const std::vector<float>& colorsStops, TexturePtr texture = nullptr);
|
||||
|
||||
void render();
|
||||
void update(double elapsedTime);
|
||||
|
@ -51,7 +51,7 @@ private:
|
|||
PointF m_position;
|
||||
PointF m_velocity;
|
||||
PointF m_acceleration;
|
||||
Size m_size;
|
||||
Size m_size, m_startSize, m_finalSize;
|
||||
Rect m_rect;
|
||||
float m_duration, m_ignorePhysicsAfter;
|
||||
double m_elapsedTime;
|
||||
|
|
|
@ -47,8 +47,8 @@ ParticleEmitter::ParticleEmitter(const ParticleSystemPtr& parent)
|
|||
m_pMaxPositionRadius = 3;
|
||||
m_pMinPositionAngle = 0;
|
||||
m_pMaxPositionAngle = 360;
|
||||
m_pMinSize = Size(32, 32);
|
||||
m_pMaxSize = Size(32, 32);
|
||||
m_pStartSize = Size(32, 32);
|
||||
m_pFinalSize = Size(32, 32);
|
||||
m_pMinDuration = 0;
|
||||
m_pMaxDuration = 10;
|
||||
m_pIgnorePhysicsAfter = -1;
|
||||
|
@ -145,13 +145,13 @@ bool ParticleEmitter::load(const OTMLNodePtr& node)
|
|||
|
||||
// visual
|
||||
else if(childNode->tag() == "particle-size") {
|
||||
m_pMinSize = childNode->value<Size>();
|
||||
m_pMaxSize = childNode->value<Size>();
|
||||
m_pStartSize = childNode->value<Size>();
|
||||
m_pFinalSize = childNode->value<Size>();
|
||||
}
|
||||
else if(childNode->tag() == "particle-min-size")
|
||||
m_pMinSize = childNode->value<Size>();
|
||||
else if(childNode->tag() == "particle-max-size")
|
||||
m_pMaxSize = childNode->value<Size>();
|
||||
else if(childNode->tag() == "particle-start-size")
|
||||
m_pStartSize = childNode->value<Size>();
|
||||
else if(childNode->tag() == "particle-final-size")
|
||||
m_pFinalSize = childNode->value<Size>();
|
||||
|
||||
else if(childNode->tag() == "particle-colors")
|
||||
m_pColors = Fw::split<Color>(childNode->value());
|
||||
|
@ -196,7 +196,6 @@ void ParticleEmitter::update(double elapsedTime)
|
|||
|
||||
for(int p = 0; p < m_burstCount; ++p) {
|
||||
|
||||
Size pSize = Size(Fw::randomRange(m_pMinSize.width(), m_pMaxSize.width()), Fw::randomRange(m_pMinSize.height(), m_pMaxSize.height()));
|
||||
float pDuration = Fw::randomRange(m_pMinDuration, m_pMaxDuration);
|
||||
|
||||
// particles initial velocity
|
||||
|
@ -210,7 +209,7 @@ void ParticleEmitter::update(double elapsedTime)
|
|||
PointF pAcceleration(pAccelerationAbs * cos(pAccelerationAngle), pAccelerationAbs * sin(pAccelerationAngle));
|
||||
|
||||
ParticleSystemPtr particleSystem = m_parent.lock();
|
||||
particleSystem->addParticle(ParticlePtr(new Particle(pPosition, pSize, pVelocity, pAcceleration, pDuration, m_pIgnorePhysicsAfter, m_pColors, m_pColorsStops, m_pTexture)));
|
||||
particleSystem->addParticle(ParticlePtr(new Particle(pPosition, m_pStartSize, m_pFinalSize, pVelocity, pAcceleration, pDuration, m_pIgnorePhysicsAfter, m_pColors, m_pColorsStops, m_pTexture)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ private:
|
|||
int m_currentBurst, m_burstCount;
|
||||
|
||||
// particles size
|
||||
Size m_pMinSize, m_pMaxSize;
|
||||
Size m_pStartSize, m_pFinalSize;
|
||||
|
||||
// particles initial position related to emitter position
|
||||
float m_pMinPositionRadius, m_pMaxPositionRadius;
|
||||
|
|
Loading…
Reference in New Issue