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

2012/7/2

'connecting objects'

Moritz Moritz

2012/7/2

#
Hey, How can I code this: there are moving objects and when the 'game figure' touches one of the objects all objects have to stop moving. I won´t code it with subclasses - how can I do that? thank you...
erdelf erdelf

2012/7/2

#
this in act, replace Figure with the name of your class:
if(getOneIntersectingObject(Figure.class) != null)
{
      Greenfoot.stop();
}
Bytelord Bytelord

2012/7/2

#
Thats shit erdelf. He wants exactly not to stop. He wants all objects of one class to stop MOVING. So he needs to reach every object thats the problem
erdelf erdelf

2012/7/2

#
At first, don't be insulting, I tried to help you. I will try it again, describe exactly what you want
nccb nccb

2012/7/2

#
Bytelord: what erdelf said, he was trying to help. As for the original question, you'll probably want to make some sort of stop() method in your Figure class. Then you need to check for touching one of them, followed by looping through all of them to call this method:
if (getOneIntersectingObject(Figure.class) != null)
{
    for (Object o : getWorld().getObjects(Figure.class)
    {
        Figure f = (Figure)o;
        f.stop();
    }
}
erdelf erdelf

2012/7/2

#
Hm, why not, you could also make a static boolean for this
Bytelord Bytelord

2012/7/2

#
@nccb that should work fine. @erdelf sry. for rage. i think you don't tried to help me, you tried to help Moritz
erdelf erdelf

2012/7/2

#
@bytelord, sry for that, my browser shows me the same name for you and moritz, (I was coding on my local files). I used the simpliest way to fix this and it was not clear what he meant
Moritz Moritz

2012/7/4

#
ok thanks for that - it works =)
You need to login to post a reply.