wang1986one / loon-simple

Automatically exported from code.google.com/p/loon-simple
0 stars 0 forks source link

为啥Sprite中的setAlpha不起作用 #48

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
程序大意为根据时间变化逐渐显示图像。

public class FirstStage extends Sprite{

    public int type = TYPE_FADE_IN;

    public float currentFrame = 0;

    private float maxFrame = 100;

    public FirstStage(String fileName){
        super(fileName);
    }

    @Override
    public void update(long timer) {
        if(type == TYPE_FADE_IN){
            currentFrame++;
            if (currentFrame <= maxFrame) {
                this.setAlpha(currentFrame);
            }
            else
            {
                this.setVisible(false);
            }
        }
        super.update(timer);
    }
}

Original issue reported on code.google.com by OGCs...@gmail.com on 20 May 2011 at 9:08

GoogleCodeExporter commented 9 years ago
也试过用currentFrame/100,限定alpha在0.0F到1.0F之间,也是没用…
…

Original comment by OGCs...@gmail.com on 20 May 2011 at 9:44

GoogleCodeExporter commented 9 years ago
找到解决方案了…… 
public void update(long timer) {
        if(type == TYPE_FADE_IN){
            currentFrame++;
            if (currentFrame <= maxFrame) {
                this.setOpacity(currentFrame/maxFrame);
            }
            else
            {
                this.setVisible(false);
            }
        }

        super.update(timer);
    }
    public void setOpacity(float opacity) {
        this.opacity = opacity;
    }
    public void createUI(LGraphics g) {
        if (!this.isVisible()) {
            return;
        }
        if (stop) {
            return;
        }
        if (opacity > 0) {
            g.setAlpha(this.opacity);
        }
        super.createUI(g);
    }

Original comment by OGCs...@gmail.com on 21 May 2011 at 5:39