0

我试图让我的粒子随着时间的推移而消失。不过,我似乎根本没有改变不透明度。知道问题是什么吗?

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);
}
4

2 回答 2

2

看起来您需要启用 alpha 混合,例如:

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

gl::drawSolidCircle(mLoc,mRadius);

gl::disableAlphaBlending();

这个讨论有更多细节:http: //forum.libcinder.org/topic/beginner-question-chang-alpha-of-a-texture#23286000000675041

于 2013-03-01T03:28:34.950 回答
0

下面的语句是增加 alpha,而不是减少它,即逐渐消失。

trans += 0.1;

将上面替换为

trans -= 0.1;

另外,我会假设您最初在构造函数或某些此类设置方法中设置“trans”。

于 2013-03-01T23:04:52.273 回答