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

2016/3/26

How to I make an Actor disappear if it touches the bottom of the screen?

IanWasHere IanWasHere

2016/3/26

#
I've tried to work this out but can't seem to figure it out... I need some help.. How do I make an Actor disappear if it touches the bottom of the world? Thanks!
xFabi xFabi

2016/3/26

#
Hey there, depending on whether you know the resolution, you could use getY() == 1080 (for 1920x1080 for example), then remove it Or use if(isAtEdge()), then remove it ( world.removeObject(this); )
danpost danpost

2016/3/27

#
IanWasHere wrote...
How do I make an Actor disappear if it touches the bottom of the world?
if (getY() == getWorld().getHeight()-1) getWorld().removeObject(this);
// or
if (isAtEdge()) getWorld().removeObject(this);
The first way is a little more precise since you specified the bottom edge of the world.
IanWasHere IanWasHere

2016/3/28

#
Now... The Block disappears when it hits the bottom... Now I want the Block to reappear in the same position and do pretty much the same thing again... How would I be able to do that?? Is it even possible?
IanWasHere IanWasHere

2016/3/28

#
IanWasHere wrote...
Now... The Block disappears when it hits the bottom... Now I want the Block to reappear in the same position and do pretty much the same thing again... How would I be able to do that?? Is it even possible?
Maybe even change size a bit as well... :)
danpost danpost

2016/3/28

#
If you want the actor to "hide" at the edge, you probably should not remove it from the world -- just zero the transparency value of its image and change it back when it moves away from the edge.
if (isAtEdge())
{
    getImage().setTransparency(0);
}
else
{
    getImage().setTransparency(255);
}
or
getImage().setTransparency(isAtEdge() ? 0 : 255);
mikemen mikemen

2016/3/30

#
Absolutely working!
You need to login to post a reply.