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

2012/1/8

Seting rotation

prti prti

2012/1/8

#
Hi, I have actor class Path with the following code
public void add()
    {
        
        Actor bee;
        bee=getOneIntersectingObject(Bee.class);
        
              

        if(bee!=null) 
        
        {
            World world;
            world=getWorld();
            world.addObject(new Camel(), getX(), getY());

             
        }
          
      
    }
This causes one new cammel to appear in the middle of the path, if bee is touching the path. I have several Path objects in my world, everyone with it's own rotation. How can the camels have the same rotation, as the object they are covering, when they appear?
Royalblue64 Royalblue64

2012/1/8

#
One way to do it would be to access the path class through the world class. You would add a bunch of paths in the world constructor, and then make a method to get a specific path. It would be very difficult however, but it would work in a similar way to the way a counter class works. You should check out how counter classes work to figure this out.
danpost danpost

2012/1/9

#
You already have a reference to the Bee class object. You could use 'bee.getRotation()' and adjust the rotation of the camel accordingly. The way to approach this, because the camel is not yet in the world, is to send the rotation of the bee to the constructor of the camel and have the camel store it in an instance variable. Then use 'addedToWorld(world)' in the camel class to set the rotation. I guess that was little round about. How about this way. Create a reference to the camel before adding it to the world, and after adding it set the rotation of the camel according to the rotation of the bee. Replace lines 12 through 14 with the following lines
Camel camel;
camel = new Camel();
World world;
world = getWorld();
world.addObject(camel, getX(), getY());
int beeRotation = bee.getRotation();
camel.setRotation(beeRotation);
prti prti

2012/1/9

#
needed rotation of the path so I modified last 2 lines, and it works.. Tnx!
You need to login to post a reply.