So I got Actor has been removed error whenever the projectile hits the edge of the world and is destroyed I've tried putting return; after the removeObject line but it is not working. Here is the superclass and subclass of the projectile:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Projectile here. * * @author (your name) * @version (a version number or a date) */ public class Projectile extends Actor { /** * Act - do whatever the Projectile wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public GreenfootImage image; public static int playerDamage; public static int enemyDamage; public Projectile(){ } Projectile projectile; public void act() { } public void Move(){ projectile = this; if(isAtEdge()){ getWorld().removeObject(projectile); return; } setLocation(getX(),getY()-2); } public void SetAsset(){ image = getImage(); image.scale(10,10); setImage(image); } public void DealDamage(int playerDamage, int enemyDamage){ if(!isAtEdge()){ Actor player = getOneIntersectingObject(Player.class); Actor enemy = getOneIntersectingObject(EnemyPlanes.class); if(player!=null){ System.out.println(enemyDamage); getWorld().removeObject(this); return; }else if(enemy != null){ System.out.println(enemyDamage); getWorld().removeObject(this); return; } else return; } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Player_Projectile here. * * @author (your name) * @version (a version number or a date) */ public class Player_Projectile extends Projectile { /** * Act - do whatever the Player_Projectile wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public Player_Projectile(){ SetAsset(); playerDamage = 5; } public void act() { Move(); DealDamage(playerDamage, 0); } }