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

2015/4/20

Hey guys I am having issues with the coding of my game for class

Regw03 Regw03

2015/4/20

#
 public void destroyEnemies()
    {
        Bird bird = getOneIntersectingObject(Bird.class);
        if(enemy != null)
        {
            World myWorld = getWorld();
            getWorld().removeObject(bird);
           
        }
        Preditor preditor = getOneInetersectingObject(Preditor.class);
        if(enemy !=null)
        {
            World myWorld = getWorld();
            getWorld().removeObject(enemy);
        }
    }
    public void kill()
    {
        Bird bird = getOneIntersectingObject(Bird.class);
        if(blueenemy != null)
        {
            getWorld().removeObject(bird);
        }
        Preditor preditor = getOneintersctingObect(Preditor.class);
        if(blueenemy !=null)
        {
            getWorld().removeObject(preditor);
        }
    }
I keep getting error notices in the fallowing areas can anyone help public void destroy enemies() public void kill() public void destroyEnemies() public void destroyEnemies()
Super_Hippo Super_Hippo

2015/4/20

#
Often the error message will tell you what to do. For example: If you use 'Bird bird = getOneIntersectingObject(Bird.class);' then you should check if 'bird' isn't null. 'enemy' is not used, so you shouldn't check for it. Something like this 'getOneintersctingObect' can't work. There are so many error in these few words.
Regw03 Regw03

2015/4/20

#
Do you mean go under the Bird class to check or something else
Super_Hippo Super_Hippo

2015/4/20

#
Bird bird = getOneIntersectingObject(Bird.class);
if (bird != null)
{
    //...
}
I think both of your methods (should) do the same. It could look like this:
Actor bird = getOneIntersectingObject(Bird.class);
if (bird != null) getWorld().removeObject(bird);

Actor preditor = getOneIntersectingObject(Preditor.class);
if (preditor != null) getWorld().removeObject(preditor);
0gener 0gener

2015/4/20

#
public void destroyEnemies()
   {
       Bird bird = getOneIntersectingObject(Bird.class);
       if(bird != null)
       {
           World myWorld = getWorld();
           getWorld().removeObject(bird);
           
       }
       Preditor preditor = getOneInetersectingObject(Preditor.class);
       if(preditor !=null)
       {
           World myWorld = getWorld();
           getWorld().removeObject(enemy);
       }
   }
You declare a Bird called bird and then check if enemy isnt null... You should check if bird or preditor are null or not.
0gener 0gener

2015/4/20

#
Or maybe im jsut confusing you issue..
Regw03 Regw03

2015/4/20

#
Ok so Ogener I replaced enemy with bird but the same error is still coming up Bird bird = getOneInetesectingObject(Bird.class); The error is Highlighting (Bird.class);
danpost danpost

2015/4/20

#
Regw03 wrote...
Ok so Ogener I replaced enemy with bird but the same error is still coming up Bird bird = getOneInetesectingObject(Bird.class); The error is Highlighting (Bird.class);
The 'getOneIntersectingObject' method returns an Actor object. It may in fact be a Bird object; but, the compiler does not know that and will not assign a variable, 'bird', that is to hold an object of type Bird with an actor it only knows to be of Actor type. Two ways to fix this:
// first way -- change the type of object 'bird' will hold:
Actor bird = getOneIntersectingObject(Bird.class);
// second way -- cast the actor to its type:
Bird bird = (Bird)getOneIntersectingObject(Bird.class);
Since you do not execute any method on 'bird' that are in the Bird class and do not use any fields that are declared in the Bird class, the first way is sufficient. It can be an Actor object to remove it (it does not have to be cast as a Bird object). However, since you are only removing those object when intersection occurs and not doing anything else, you could just use this:
public void destroyEnemies()
{
    removeTouching(Bird.class);
    removeTouching(Preditor.class);
}
Regw03 Regw03

2015/4/20

#
Ok that Worked thankyou
Regw03 Regw03

2015/4/22

#
ok now what would be the best way to attach my bullet to my character and make it fire and reload im reading about it and its a lil over my head
You need to login to post a reply.