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

2018/2/19

How to make an invisible wall?

LarsisYoloo LarsisYoloo

2018/2/19

#
Hey everybody, I've put a photo from a house in my game, but now i want to make something so that if my character moves to a table, for example, that its getting stopped by that invisible object. How do i make an invisible object?
Vercility Vercility

2018/2/19

#
Put a transparent object where the table is and stop move() from working when the resulting location touches it OR specify x/y coordinates your actor can't enter
public void repell () {
If(actor.getX() >= X && actor.getX() <= X2) {
   If(... Y.... Y2) {
      // find out from which direction you're
      // coming, (current coordinates - Middle
      // of area

      // move out of area in same direction 
   }
 }
} 
On my phone right know so I can't really write much explicit code
danpost danpost

2018/2/19

#
Why not just put a table there and set the transparency of its image to zero; then use normal collision detection to stop the actor.
Vercility Vercility

2018/2/19

#
danpost wrote...
Why not just put a table there and set the transparency of its image to zero; then use normal collision detection to stop the actor.
That's exactly what I said isn't it ¯\_(ツ)_/¯
LarsisYoloo LarsisYoloo

2018/2/19

#
Vercility and danpost, thanks for the reactions, I've cut the table out of my background, and replaced it in a class, then used this code:
public void setLocation(int x, int y)
{
    int oldX = getX();
    int oldY = getY();
    super.setLocation(x, y);
    if(!getIntersectingObjects(Table.class).isEmpty())
    {
        super.setLocation(oldX, oldY);
    }
}
It is now fixed. Thank you guys
danpost danpost

2018/2/19

#
Vercility wrote...
<< Quote Omitted >> That's exactly what I said isn't it ¯\_(ツ)_/¯
Sorry, I only saw your post when the page loaded (never saw the original post by LarsisYoloo).
You need to login to post a reply.