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:
       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:
getWorld().removeObject(this);
Matetity Matetity

2023/11/15

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