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

2015/10/30

object pick up

javastudent javastudent

2015/10/30

#
My teacher wants us to make an object( let's say a car) pick up another object. And that the car should pick the other object up if the car touches it and that the other object has to move to wherever the car is going. PLEASE HELP. I'VE BEEN TRYING TO FIGURE IT OUT BUT IT'S REALLY HARD.
Genora51 Genora51

2015/10/30

#
if you know what the actor class is (car in this case), you could put a bit of code like this in the object to pick up's act method:
1
2
3
4
if(isTouching(car.class)){
    car c = (car) getOneIntersectingObject(car.class);
    setLocation(c.getX(),c.getY();
}
javastudent javastudent

2015/10/31

#
Thank you. But I also need help with this. While carrying the object, if the spacebar is pressed, the car should drop the object at the point where it is currently located. How to do this?
danpost danpost

2015/10/31

#
I would suggest you control the object being picked up from the class of the object picking it up. If you code it in the class of the object being picked up, then any and all objects that can be picked up will act independently and you could have multiple objects picked up at one time.
You need to login to post a reply.