I admit I’m new to trying to write on a blog regularly, but seems like everyone says the trick is just to talk about anything you work on, so, onward with the overly verbose rambling of the gui work I’m doing…
Part of our UI design called for a world map, that lets the player click on locations to move to them, rather than just having static buttons in a grid on the screen. As part of this, we needed a tank sprite to travel from location to location.
I didn’t want to have to come up with some sort of dynamic pathing system to find and follow paths on its own, since its just a gui afterall. So to start with, I created a dozen or so short t2dPath segments, with a long list of variables telling it which paths make up the complete path from location A to location B. This worked fine when you were going the correct direction, but then coming the other way, the path segments resulted in a back and forth movement as the tank traveled to the far end, followed the path back, then repeated with the next. Trying to determine the right direction ended up getting complex, as the direction to take on the path segments could change from subpath to subpath.
So I deleted all those paths, and just put in a bunch of t2dSceneObjects (since they arn’t visible) along all the roads and changed my variables listing the subpaths to take, to listing the nodes to moveTo. Few minutes changing variables and function calls in my previous script, and pathing now works smoothly between all the locations on the map.
To index into my route variables, I gave each location a value following the binary pattern (1, 2, 4, 8, etc) so any two locations added together give a unique number, letting me index in with something like $route[$theNest + $gooGoo]; and then theres a separate set of variables telling me which of the two nodes for each index is the starting point in the list, so I know when I have to go “backwards’ rather than forwards. Theres a ton more variables doing it this way than I usually like to have, but it was the simplest way to set it up I could think of, and didn’t really take all that long to create everything by hand.
Not really an impressive screenshot since this is code rather than art (and the map Nauris drew is already in the gallery), but what the heck, rather not post without at least one image (I am primarily an artist afterall…)