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

2011/12/2

Get number from another object

Gazzzah Gazzzah

2011/12/2

#
Hello, For my major work in software development I will need a motion parenting mechanism. However I am relatively new to Greenfoot and I'm not entirely sure how to use the "get" methods. It would be awesome if I could tell object "A" to get "number" from object "B". I looked at the Greenfoot API and found some useful things like "getObjects()" and "getObjectsInRange()". I imagine it would go something like: getWorld().getObjects(B.class).getNumber() (assuming I've pre-wrote a getNumber Method) However, whatever I do I can't figure it out. A little help please?
MeCanta MeCanta

2011/12/2

#
Hi, do you mind sharing with us what major work in software development you're referring to?
Gazzzah Gazzzah

2011/12/2

#
MeCanta wrote...
Hi, do you mind sharing with us what major work in software development you're referring to?
For school. I am to develop a piece of software of my choice in the structured approach. I am making a top-down, wave based survival game. Some of the enemies have moving parts (eg a rotating turret or a spike that thrusts out). For these moving parts I will need them to be able to update position or rotation by getting it from the other class. Hope that's helpful.
Morran Morran

2011/12/2

#
If they are intersecting objects, like a turret would intersect a tank or base, you could have the turret call:
Base base = (Base) getOneIntersectingObject(Base.class);
if(base != null) {//should not be null, unless the turret does not really intersect a base
   setLocation(base.getX(), base.getY());
}
Or, you could have it work off of a parent system. In the Base class, you could have "private Turret myTurret;"(an instance variable), and then in Base's "act()" method, it would update "myTurret" 's position.
Gazzzah Gazzzah

2011/12/3

#
Morran wrote...
Or, you could have it work off of a parent system. In the Base class, you could have "private Turret myTurret;"(an instance variable), and then in Base's "act()" method, it would update "myTurret" 's position.
The MyTurret sounds like the right option, seems more reliable and logical. How might I go about doing that in code?
You need to login to post a reply.