Loading svg removes elements from the screen

Hi all,

I'm making an interactive animation where I display different animated elements depending on which key is pressed. I trigger different classes with basic shapes that are animated. All goes well except when I run animations that have an svg file as a base shape. Then all other animations in the same area are cleared from view. They pop back up (and have been running in the background somehow) once the svg animation is removed from the screen using ArrayList.remove(). I've searched but I haven't found a solution to this problem. I hope someone can point me in the right direction?

Thanks very much in advance, Danielle.



  • Your description is insufficient to allow us to help you.
    We probably need to see your code.
    If it is lengthly, it would be nice to be able to reduce it to a minimum showing the problem.

  • edited March 2015

    OK, sorry about that, I just wondered if it was a common problem with a know solution... If just post one of the conflicting classes and the way they are called in the main draw() function.

    I call the classes in the draw function one after another. Maybe the stacking is a problem here?

    If I click a certain key the doBee is activated:

        // init bee
        for(int i = 0; i < beeAmount; i++){
          bees.add(new BeeVehicle(10, random(height-100,height-150)));
          if(wind.x < 0)
            beeTarget = new PVector(width-random(50,200), random(height-50,height-100)); 
            beeTarget = new PVector(random(50,200), random(height-50,height-100)); 
        doBee = false; // turn off
      // move bee
      if(bees.size() > 0){
        for(int i = bees.size()-1; i >= 0; i--){
          BeeVehicle b = bees.get(i);
            if(wind.x < 0)
              beeTarget = new PVector(b.location.x-random(100,300), b.location.y+b.distance); 
              beeTarget = new PVector(b.location.x+random(100,300), b.location.y+b.distance); 
          // check edges


    The BeeVehicle class:

        class BeeVehicle{
          PVector location, velocity, acceleration;
          float maxspeed;
          float maxforce; // limit maximum steering force
          float r;
          int distance;
          int hesitation, hesitationMax;
          PShape bee;
          PVector prevTarget;
          BeeVehicle(float x, float y){
            acceleration = new PVector(0,0);
            velocity = new PVector(0,0);
            if(wind.x > 0){ // left
              println("from left");
             x = 0-x; // make negative 
            } else {
              x = width+x;
            location = new PVector(x,y);
            r = 3.0;
            maxspeed = 2;
            maxforce = 0.1;
            distance = 25; // distance to target
            hesitation = 0;
            hesitationMax = 100;
            bee = loadShape("bee.svg");
            prevTarget = location;
          void update(){
          void applyForce(PVector force){
          boolean seek(PVector target){
            PVector desired = PVector.sub(target,location);
            float d = desired.mag();
            boolean found = false;
            if(d < distance){
              prevTarget = target;
              float m = map(d,0,distance,0,maxspeed);
              desired.y -= 100;
              if(hesitation > hesitationMax){
                found = true;
                hesitation = 0;
            } else {
            PVector steer = PVector.sub(desired,velocity);
            return found;
          void display(){
            translate(location.x, location.y);
            if(wind.x > 0){ // to the right    
              scale(-1.0, 1.0);
            } else {  
              shape(bee, 0,0);
          boolean isOutside(){
            if(location.x > (width + 20) || location.x < (0 - 20) || location.y > height || location.y < 0){
              return true;
            } else {
              return false;

    I'm sorry for the formatting (I selected and hit ctrl-O). I can't get it right. But I hope this gives you more insight in what might be wrong. Thanks for your time.

  • edited March 2015

    Formatting: you need empty lines around the code. I added them. And don't indent the plain text lines!

  • Thanks for you help. Any ideas what might be the cause of elements disappearing when the svg element is displayed? TIA.

Sign In or Register to comment.