0
votes

I'm building a model that has a population of agents in "main" that have a rectangular node as part of their definition - let's call them "pen" agents. I am building my animation at the main level and programmatically locating the "pen" agents by setting their X-Y coordinates (setXY()) - the images of the pens are appearing at the expected locations on my canvas. When I run my model and tell my moving agents (let's call them "sheep") to move along paths to nodes that have been defined on "main" they move as expected. However, when I tell my "sheep" to move to the nodes that exist in my "pen" objects, the sheep just move as though the "pens" are located at the (0,0) location.

I have tried all kinds of combinations of the "visible" and "visible on upper level" options on both the population and the "pen" presentation items but I still can't get the behaviour I am after. How do I get the nodes in my sub "pen" agents to be correctly recognised at the "main" level?

An image tells a thousand words:

Animation on "main"

1
what happens if you try sheep.setLocation(pen.theNode);? - Felipe
Hi Felipe, thanks for the hint - greatly appreciated. It is a very strange thing... using sheep.setLocation(pen.theNode); correctly positions the sheep in the center of the pen node. However sheep.moveTo(pen.theNode); moves the sheep to the (0,0) location on the main canvas. So setLocation() and moveTo() use different coordinate systems.... Unfortunately setLocation() doesn't really achieve the effect I am after as there are seized resources that need to move with the sheep and I'd like to display the movement occurring rather than the sheep just jumping to the pen location. - CrustyNoodle

1 Answers

0
votes

OK, I have found a solution which works for my circumstances however I'm not entirely happy with it as it seems a bit too "manual". All I did was to create the "pen" node at run time and set its owner to main like so:

node = new RectangularNode();
node.setOwner(main);
node.setPos(x, y, 0);
node.setSize(width, height);
node.initialize();

I got the x & y coordinates and width & height dimensions from the originally created node in my "pen" class. I think this is a far from elegant solution however, so if anyone can suggest a better one then "I'm all ears".