2 Replies Latest reply on May 27, 2008 10:42 AM by voguecreative

    Arrays and Collisions

      Hi everyone. I'm creating a billiard/snooker/pool game. I've created a colision detect function which runs on every onEnterframe to check if the white ball has collided with another ball. I am able to get it working with one redball but not with the others. Im not too sure how to set up an array and call the movie clips thats way?

      Im pretty sure it can be easily simplified but i cant figure out how!

      Please help!

        • 1. Arrays and Collisions
          clbeech Level 3
          just scanning this briefly, I'd say that you'd be far better off using a shape based collision detection system like that of Grant Skinners - OR build your own system using Bitmap.hitTest (which is what Grant's uses but only compares two MC instances per iteration) I would also prefer to build a class for each ball instance, and have each instance run it's own checks against the entire field at once and track it's own properties, like heading, velocity, friction, type, color, etc. - then if a hit is determined pass the vector info to the other ball instance after performing the appropriate calculations OR pass them and have the receiving ball perform it's own vector modifications. This would save the lengthy process of testing each prop in a single pass as well - let each instance control itself in other words. There is some more discussion on hitTesting HERE and some bitmap hitTesting examples HERE (however they are running a bit slow atm since there are two within the post - normally my example run at around 22+fps with 40 instances) this should give you a few more thoughts on how to construct this. I realize that this doesn't really answer your query however, so...

          to place instance into an array you write:
          var my_array = [ instance1, instance2, ... instanceZ ];

          to call an instance from an array you write:
          my_array[index]._x = newXpos;

          where 'index' is the value of the instance at that position in the array, remember that arrays are 'zero' based - that is the first index is 0. so to iterate through the entire array we use a FOR loop, this would create a 'new' property called 'instanceIndex' of the Object at that index in the array and assign it the value of it's current position in the array. just a basic example:
          • 2. Re: Arrays and Collisions
            voguecreative Level 1
            Hi. thanks for your reply, but im a bit confused by your answer. Here is a link to my fla file: http://www.mediafire.com/?wd5im9mnykz

            so you can see how i have set up the game.