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

2017/3/21

removeTouching doesn't work

vijer vijer

2017/3/21

#
What am I doing wrong. if (this.isAtEdge()) { removeTouching(Ball.class); }
Super_Hippo Super_Hippo

2017/3/21

#
What do you want to remove?
vijer vijer

2017/3/21

#
Super_Hippo wrote...
What do you want to remove?
The theBall created in the MyWorld class. addObject(theBall, 400, 300);
Super_Hippo Super_Hippo

2017/3/21

#
And the code is in the same class?
1
2
3
4
if (isAtEdge())
{
    getWorld().removeObject(this);
}
As you have it, the condition doesn't really fit to what should happen.
vijer vijer

2017/3/22

#
Super_Hippo wrote...
And the code is in the same class? As you have it, the condition doesn't really fit to what should happen.
So, when and how would we use removeTouching ?
Nosson1459 Nosson1459

2017/3/22

#
When are you removing the ball and where is the code being that does it? (You want to remove the ball when what hits the edge?)
vijer vijer

2017/3/22

#
Nosson1459 wrote...
When are you removing the ball and where is the code being that does it? (You want to remove the ball when what hits the edge?)
theBall is an Actor and when it hits the edge of the World I want it to be removed. The code is in Ball class. Apparently, removeTouching can't be used in that scenario, so when and how is it used?
Super_Hippo Super_Hippo

2017/3/22

#
You can use removeTouching if you want to remove an object which touches the ball. For an example. You have an animal which walks around and eats food.
1
removeTouching(Food.class);
vijer vijer

2017/3/22

#
Super_Hippo wrote...
You can use removeTouching if you want to remove an object which touches the ball. For an example. You have an animal which walks around and eats food.
1
removeTouching(Food.class);
But you can't use it to remove theBall when it goes off the edge of the world?
Nosson1459 Nosson1459

2017/3/22

#
vijer wrote...
But you can't use it to remove theBall when it goes off the edge of the world?
If you want to remove the Ball when it goes off the edge of the screen, then you can put in the Ball class:
Super_Hippo wrote...
1
2
3
4
if (isAtEdge())
{
    getWorld().removeObject(this);
}
You need to login to post a reply.