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

2023/11/13

Need help with removing object

Matetity Matetity

2023/11/13

#
My Bullet class should be removed if it touches the wall, but it doesn't. Here is my code of my Bullet:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
    public void act()
{
    move(5);
    removeP();
    removeB();
}
public void removeB()
{
  if(isTouching(wall.class))
  {
      removeTouching(Bullet.class);
     }
 }
public void removeP()
{
    if(isTouching(player.class))
    {
      removeTouching(player.class); 
       
     }
}
public Bullet()
 {   
     GreenfootImage image = getImage();
     image.scale(image.getWidth() - 60, image.getHeight() - 60);
     setImage(image);
 
Powerdotpaint Powerdotpaint

2023/11/13

#
no you should use remove object i wish iam right
danpost danpost

2023/11/14

#
Powerdotpaint wrote...
no you should use remove object i wish iam right
You are right. Change line 11 to the following:
1
getWorld().removeObject(this);
Matetity Matetity

2023/11/15

#
thank you so much, it works now!!
You need to login to post a reply.