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

2012/2/25

How I could do that?

TopInPut TopInPut

2012/2/25

#
If I wanna say that if my actor eats something the world should add the object again. I could say:
if(eatLeaf()) {   //as example
x = x +1 ;
Leaf leaf = (Leaf) getOneObjectAtOffset(0, 0, Leaf.class);
leaf.setLocation(x, y);
}
But i wanna add a new Leaf too. How could I ?
danpost danpost

2012/2/25

#
I am assuming that 'eatLeaf()' does nothing more that returns a boolean value depending on whether a leaf is intersecting the Actor or not. You code says to take the current (intersecting) leaf and move it one grid to the right. Now, assuming you want to add the new leaf at the same location (though you may want to place it randomly on your grid) 'getWorld().addObject(new Leaf(), x, y);' would do the trick (just set up x and y to appropriate random values for anywhere).
You need to login to post a reply.