summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/imageparticle.cpp10
-rw-r--r--src/particle.cpp13
-rw-r--r--src/particle.h3
-rw-r--r--src/textparticle.cpp10
4 files changed, 18 insertions, 18 deletions
diff --git a/src/imageparticle.cpp b/src/imageparticle.cpp
index feb9548d..8ef2cce9 100644
--- a/src/imageparticle.cpp
+++ b/src/imageparticle.cpp
@@ -56,14 +56,6 @@ void ImageParticle::draw(Graphics *graphics, int offsetX, int offsetY) const
return;
}
- float alphafactor = mAlpha;
-
- if (mLifetimeLeft > -1 && mLifetimeLeft < mFadeOut)
- alphafactor *= (float) mLifetimeLeft / (float) mFadeOut;
-
- if (mLifetimePast < mFadeIn)
- alphafactor *= (float) mLifetimePast / (float) mFadeIn;
-
- mImage->setAlpha(alphafactor);
+ mImage->setAlpha(getCurrentAlpha());
graphics->drawImage(mImage, screenX, screenY);
}
diff --git a/src/particle.cpp b/src/particle.cpp
index 84161c9f..0c4a7d7e 100644
--- a/src/particle.cpp
+++ b/src/particle.cpp
@@ -393,6 +393,19 @@ void Particle::adjustEmitterSize(int w, int h)
}
}
+float Particle::getCurrentAlpha() const
+{
+ float alpha = mAlpha;
+
+ if (mLifetimeLeft > -1 && mLifetimeLeft < mFadeOut)
+ alpha *= (float)mLifetimeLeft / (float)mFadeOut;
+
+ if (mLifetimePast < mFadeIn)
+ alpha *= (float)mLifetimePast / (float)mFadeIn;
+
+ return alpha;
+}
+
void Particle::setMap(Map *map)
{
mMap = map;
diff --git a/src/particle.h b/src/particle.h
index 0690e8c4..69f8c2be 100644
--- a/src/particle.h
+++ b/src/particle.h
@@ -286,6 +286,9 @@ class Particle : public Sprite
{ return 1; }
protected:
+ /** Calculates the current alpha transparency taking current fade status into account*/
+ float getCurrentAlpha() const;
+
bool mAlive; /**< Is the particle supposed to be drawn and updated?*/
Vector mPos; /**< Position in pixels relative to map. */
int mLifetimeLeft; /**< Lifetime left in game ticks*/
diff --git a/src/textparticle.cpp b/src/textparticle.cpp
index e6226449..c9b5fc18 100644
--- a/src/textparticle.cpp
+++ b/src/textparticle.cpp
@@ -44,16 +44,8 @@ void TextParticle::draw(Graphics *graphics, int offsetX, int offsetY) const
int screenX = (int) mPos.x + offsetX;
int screenY = (int) mPos.y - (int) mPos.z + offsetY;
- float alpha = mAlpha * 255.0f;
-
- if (mLifetimeLeft > -1 && mLifetimeLeft < mFadeOut)
- alpha = alpha * mLifetimeLeft / mFadeOut;
-
- if (mLifetimePast < mFadeIn)
- alpha = alpha * mLifetimePast / mFadeIn;
-
gcn::Color color = *mColor;
- color.a = (int)alpha;
+ color.a = getCurrentAlpha() * 255;
TextRenderer::renderText(graphics, mText,
screenX, screenY, gcn::Graphics::CENTER,