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

2011/8/23

Please help

Slinger Slinger

2011/8/23

#
Is there a way to get a object to hide when its touching the edge of the world? (i'm new so if this is dumb question you know why XD)
kiarocks kiarocks

2011/8/23

#
is this all edges, or just the sides?
danpost danpost

2011/8/23

#
The pseudo-code is: If touching left edge, then hide object If touching top edge, then hide object If touching right edge, then hide object If touching bottom edge, then hide object The easiest way to hide an object is to set its transparency to zero. The object will not be visible, but it is still there and the act() method will still perform on this object. I can think of two ways to avoid this (at the moment). The first is to put any action you do not want to happen while it is hidden in an 'if (getTransparency() != 0)'. The other is to, instead of changing the trasparency to zero, remove the object entirely (and re-create it if and when the time comes to 'un-hide' the object). You need to decide which edges are pertinent, and which method is best for your scenario. For left edge, use 'if (getX() < getWidth() / 2)', replace 'getX()' with 'getY()' and 'getWidth()' with 'getHeight()' for top edge. For right edge use 'if (getX() > (getWorld().getWidth() - getWidth) / 2)', and use the same replacements for the bottom edge.
Slinger Slinger

2011/8/24

#
Whats the code for if touching bottom edge? I tried everything i could think of.
Busch2207 Busch2207

2011/8/24

#
Try this:
public boolean AtWorldEdge()
{
double w=getImage().getWidth()/2,h=getImage().getHeight()/2
return getX()==w || getY()==h || getX()==getWorld().getWidth()-(w+1) || getY()==getWorld().getHeight()-(h+1);
}
I haven't tried it, but I think, it works! ;)
Slinger Slinger

2011/8/24

#
Where should i put it? nvm i figured it out :D thank you!
You need to login to post a reply.