This site requires JavaScript, please enable it in your browser!
Greenfoot back
GreenfootNewbie
GreenfootNewbie wrote ...

2015/5/8

Please help. I am having trouble making an object transparent

1
2
ipeefreely ipeefreely

2015/5/10

#
danpost Thanks man but I keep getting error messages using Super_Hippos exact code below.
private int blinkTimer=5, t=1;
    public void act()
    {
        blinkTimer--;
        if (blinkTimer == 0)
        {
            blinkTimer = 5; //smaller number => faster blinking
            t = (t+1)%2;
            getImage().setTranparency(t*255);
        }
    }
The Greenfoot error comes after I compile and says "cannot find symbol - method setTransparency(int)" Would this also work by speeding up the process in Greenfoot too if one didnt know about timers?
danpost danpost

2015/5/10

#
The method name is not spelt correctly -- it is not 'setTranparency', but 'setTransparency' (with the 's').
Super_Hippo Super_Hippo

2015/5/10

#
Well, I missed an "s" there. It's "Transparency" and not "Tranparency". But I wonder why the error message has this "s" there.
ipeefreely ipeefreely

2015/5/10

#
Super_Hippo wrote...
Well, I missed an "s" there. It's "Transparency" and not "Tranparency". But I wonder why the error message has this "s" there.
danpost & Super_Hippo, thank you both. I just compiled & got no errors. The error message I had to type out & typed/spelled it correctly
aromero2 aromero2

2015/7/17

#
It could also look something like this:
 public void act()
    {
        GreenfootImage i = getImage();
        int t = i.getTransparency();
        i.setTransparency(0);
        Greenfoot.delay(1);
        i.setTransparency(t);
        Greenfoot.delay(5);

    }
danpost danpost

2015/7/17

#
@aromero2, the code you gave may work; however, be aware that using 'delay' to animate something will cause the rest of the scenario to freeze during the animation. With your code, the freezing will occur during each blink cycle which would make everything else appear to slow down instead of freeze (continuous series of short-time freezing). I guess what I am trying to say is that the 'delay' will be applied to everything within the scenario; not just the object that animates.
You need to login to post a reply.
1
2