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

2015/1/19

Fading Timer and Hovering

Ariadia Ariadia

2015/1/19

#
Two questions.. I need to have my object fade in transparency over time. If the object catches food, it returns to normal and starts the fading loop again. What is the easiest way to do this? Also, I need that same object to hover up and down, should I just make a gif and put it in as a looping animation or is there a way to do this in the code. I looked at the jumping and falling code, but that didn't work. Quick responses would be sincerely appreciated! :) Please and Thank you!
Super_Hippo Super_Hippo

2015/1/19

#
1
2
3
4
5
6
7
8
9
10
public void act()
{
    int r = getImage().getTransparency();
    if (r>0) r--;
    //when food was eaten
    {
        r = 255;
    }
    getImage().setTransparency(r);
}
I think manually animate the images is the only way.
danpost danpost

2015/1/19

#
You can use the Actor object method 'getImage' to get the GreenfootImage that is currently assigned to the actor and then use the GreenfootImage object methods 'getTransparency' and 'setTranspaency' to deal with the fading of the image. You can add an int field to use as a timer to slow down the fading process and possibly to delay it as well.
Ariadia Ariadia

2015/1/20

#
Thank you so much! The fade works correctly now. :) As for the hover, If I do animate it out of the program, will the code still work with it? For example, if I have the object getting the ground at offset, will it change? Or does it work with a bounding box? (Does that question make sense?)
danpost danpost

2015/1/20

#
Ariadia wrote...
As for the hover, If I do animate it out of the program, will the code still work with it? For example, if I have the object getting the ground at offset, will it change? Or does it work with a bounding box? (Does that question make sense?)
It is unclear what you mean by animating the hover out of the program as all animation must be done through code. Also, 'the code' in 'will the code still work' can only be presumed to be the fading code, where fading and hovering have nothing to do with each other unless you specifically add code to have the state of one cause a change in the other. Then, with your example, 'I have the object getting the ground at offset, will it change', again I will have to presume that 'it' refers to the fading code; and again, the transparency of the image does not change the size of the image or how it is perceived by collision detection methods. Finally, 'bounding box' is maybe supposed to be 'bouncing box' -- but, I cannot be certain. But, still again, I cannot make any connection to the transparency of the image in either case.
You need to login to post a reply.