Forum: Animation


Subject: Flash advanced user : Please Help Me !!!!!!!!!!!!!!!!!

remc opened this issue on Sep 04, 2002 ยท 2 posts


vectortv posted Sat, 07 September 2002 at 6:04 PM

Well there are a couple of ways to action this environment. The first (and most simplest) is to use the 'hittest' function. You basically attach a movie clip to the mouse, and then when you have the on (mousedown) it checks the hittest to see if it connects with the object - you could either have it list all the movie clips on the stage and check each one, or put the movie clip names all into an array and then create a loop that checks them all. However what will happen with this way is that you only allow them to move if they don't click on an object. The second and FAR more complicated way is to use pathfinding metholodology, and here's where it gets a bit complicated. What you basically need to do is turn your stage into a grid, of tiny square, and then put your objects into movie clips and dynamically attach them to the stage, and push that into an array - at the same time you reference another array with a single variable which tells whether the user can move to this square or not for example - a 9 x 9 grid below: 000000001 000000001 000000001 000001111 110000000 110000000 000011000 000011000 000000000 The ones would identify what squares the user can't move to. Then what we do is initialise a variable to declare where the user is. When they click on the square the movie clips tells it where in the grid that is and whether the user can move to it, if not you tell it to move to the nearest square. That's a very simple way, if you wanted to work in a more complicated but cleaner image (like Diablo II) do a search for pathfinding.