Question

I'm trying to have my particles fade away with time. I don't seem to be changing the opacity at all though. Any idea what the problem is?

class Particle
{

public:

    Particle();
    Particle( ci::Vec2f );
    void update();
    void draw();

    ci::Vec2f   mLoc;
    ci::Vec2f   mDir;
    float       mVel;
    float       trans;

    ci::ColorA       mColor;
    float           mRadius;

    float col_1,col_2,col_3;
};


void Particle::update()
{
  mLoc+=mDir*mVel/2;
  trans+=0.1;
  mColor=ColorA(col_1,col_2,col_3,trans); 
}

void Particle::draw()
{ 
 gl::color(mColor);
 gl::drawSolidCircle(mLoc,mRadius);
}
Was it helpful?

Solution

It looks like you need to enable alpha blending for example:

gl::enableAlphaBlending();
gl::color( mColor );

gl::drawSolidCircle(mLoc,mRadius);

gl::disableAlphaBlending();

This discussion has more details: http://forum.libcinder.org/topic/beginner-question-changing-alpha-of-a-texture#23286000000675041

OTHER TIPS

The below statement is increasing alpha, not reducing it, i.e. fading away.

trans += 0.1;

Replace above with

trans -= 0.1;

Also, i would assume that your setting 'trans' initially in the constructor or some such setup method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top