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

2013/5/18

Separating the viewed location of actors from their physical location

m_p_v_13 m_p_v_13

2013/5/18

#
Does anybody know how to separate the viewing field from the actual location of the actors? I am making a program modeling runners in a foot-race and was able to wrap the world, but in doing so, I also altered the physical location of the actors themselves, making them not interact correctly with the other actors. Is there a way to view them wrapping around the edges, but have them physically not altered? This is a link to what I have so far: http://www.greenfoot.org/scenarios/7518
danpost danpost

2013/5/18

#
Yes, there is a way. However, it requires treating the actor as it was at both locations (where it is in the world at the moment and at its wrapped position off the other edge of the world. You only need to check the wrapped location when the actor intersects the edge of the world. I will presume you already are using an unbounded world (one created with a 'super(int, int, int, boolean)' with the boolean value set to 'false'. To check the wrapped position, first move the actor to that position and perform your checks, then move it back to its original location in the world.
m_p_v_13 m_p_v_13

2013/5/19

#
Thank you! Do you have a program that exemplifies this technique that I could see? My original program was taken from a standard Boids model, and I added world wrapping so that when the actor got to the edge of the viewing field it would physically move back to the beginning.
danpost danpost

2013/5/19

#
The only thing I have right now is my 'Game of Life' scenario that requires finding each edge cells neighbors on the opposite edge when wrapping is enabled. The source is not given for that scenario; but for what you want, this would be a very brief example; and besides, it is a gridded world, to boot.
You need to login to post a reply.