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

2015/9/27

addObject/removeObject/isAtEdge...

Vellyxenya Vellyxenya

2015/9/27

#
Hi, until now the objectswere removed when their x-location(the middle of their width) was at the edge of the world, and the same when they were created. However, I created a created an actor with a big image and I want him to appear gradually, from the right, pixel by pixel (i don't want the half of its image to appear instantly in one second) how can i do that please?^^
danpost danpost

2015/9/27

#
Vellyxenya wrote...
I want him to appear gradually, from the right, pixel by pixel (i don't want the half of its image to appear instantly in one second) how can i do that please?^^
There are two ways to accomplish that. One is the create an unbounded world (one in which actors are allowed to go beyond the bounds of the visible world). You can check out the World class constructors for that. The other way is to have the image of the actor "grow" while the actors location is at the edge of the world. This would be done something like this:
// instance field
private GreenfootImage baseImage;
// in constructor
baseImage = getImage();
setImage(2-baseImage.getWidth()%2);
// method to set image
private void setImage(int width)
{
    GreenfootImage setter = new GreenfootImage(width, baseImage.getHeight());
    setter.drawImage(baseImage, 0, 0);
    setImage(setter);
}
// in act
int imageWidth = getImage().getWidth();
if (imageWidth < baseImage.getWidth()) setImage(imageWidth+2); else move(-1);
Vellyxenya Vellyxenya

2015/9/28

#
Thank you very much, it works perfectly ! :)
You need to login to post a reply.