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

2019/1/5

Help with method issue in greenfoot

aa124 aa124

2019/1/5

#
public void move() { setLocation(getX()+vx,getY()); Actor actor = getOneIntersectingObject(Rocket.class); if(actor!=null) { ((Rocket)actor).destroyed(); destroyed(); } if(getX()<-200) { toRemove=true; } } public void destroyed() { for(int i=0; i<10;i++) { int px =-20+Greenfoot.getRandomNumber(40); int py =-20+Greenfoot.getRandomNumber(40); getWorld().addObject(new Explosion(getImage()),getX()+px,getY()+py); } getWorld().addObject(new Circle(),getX(),getY()); toRemove=true; } Im trying to call the destroyed method on the ((Rocket)actor).destroyed(); However, I receive an error from greenfoot even though the destroyed method is right under it.
Super_Hippo Super_Hippo

2019/1/5

#
This code is probably in a class named Bullet (or something similar). In the class Rocket, there is no destroyed method. The line below which is calling the method right below should work.
You need to login to post a reply.