Hi! I encountered a problem with a projectile which has to explode on touch with an actor. It has a delay to display the gif when at a long distance from the starting location and when it hits at a middle distance it just doesn't display it at all, or only a few frames after a delay. On short distance though, it works perfectly fine. It's instant and displayed properly. What might be the cause of this problem be? Here's the code for the bullet class:
import greenfoot.*;
public class bossBullet extends Misc
{
public int speed =10;
public int counter = 0;
public int check = 1;
public int nr = 0;
public int ok = 1;
public bossBullet(double mouseRotation)
{
setRotation((int)mouseRotation);
}
GifImage gif = new GifImage("bossBullet.gif");
GifImage gif1 = new GifImage("bossBulletExpl.gif");
public void act()
{
if(check==1)
{
setImage(gif.getCurrentImage());
remove();
move(speed);
if((isTouching(Odobasian.class) || isTouching(Pepsi.class)) && ok==1)
{
((level)getWorld()).health--;
check=0;
}
}else explosion();
if(counter==60)getWorld().removeObject(this);
}
public void remove()
{
if(isTouching(portal.class))getWorld().removeObject(this);
else if(isTouching(Surface.class) ){ok=0;explosion();}
else if(getX()>=getWorld().getWidth() -1){ok=0;explosion();}
else if(getX()<1){ok=0;explosion();}
else if(getY()>=getWorld().getHeight() -1){ok=0;explosion();}
else if(getY()<1){ok=0;explosion();}
}
public void explosion()
{
counter++;
setImage(gif1.getCurrentImage());
if((isTouching(Odobasian.class) || isTouching(Pepsi.class)) && nr<1)
{
((level)getWorld()).health-=1;
nr++;
}
}
}
