Jump to content

[SOLVED] WidgetSprite::setColor will cause sprite disappear when color.w > 1


photo

Recommended Posts

Posted

I found this when I'm writing sprite fade in/out script. sometime when color.w > 1 for example, color.w = 1.007, the sprite will disappear randomly. means it will not always disappear, only sometime.

 

for example in this code

 

        float t=0, d=0.8, t2;
        while(t<d) {
            t += engine.game.getIFps();
            t2 = t/d;
            if(t2 < 0.5) {
                mask_color.w = 1 - t2 * 2;
                info_s[1].setColor(mask_color);
            }else {
                if(info_s[1].getTexture() != xn.getArg("sprite"))
                        info_s[1].setTexture(xn.getArg("sprite"));
                
                mask_color.w = t2*2 - 1;
                if(mask_color.w > 1) mask_color.w = 1;
                info_s[1].setColor(mask_color);
            }
                       
            wait;
        }

 

in this code I want the sprite fade out and load another texture then fade in, if you write this in update() function

 

vec4 c = info_s[1].getColor();
engine.message("mask alpha: %.3f", c.w);

 

and try some time, you will see when the alpha > 1.0f, then sometime the sprite disappeared.

Posted

thanks, this solved problem, but why don't add this check in C++ part, so other people won't have my problems.

×
×
  • Create New...