2 Replies Latest reply on Jul 6, 2010 6:13 AM by srd49

    Basic Collision - How? :(


      Hey, I´m new on programming in action-script.

      I know another progamming langue.


      But, anyway. How do i do this?


      if left key is pressed and place is free to the left. THEN do: Move to left


      in my old programmin langue it was like this:

      if keyboard_check(vk_left) and place_free(x-10,y){




      But how do i do it in flash? (if left key is pressed and place is free to  the left. THEN do: Move to left)


      Help plz

        • 1. Re: Basic Collision - How? :(
          kglad Adobe Community Professional & MVP

          there's nothing like a place_free() in actionscript.  you can check if an object is at that x,y but that won't necessarily be what you want.

          • 2. Re: Basic Collision - How? :(



            For Flash to know the left key is pressed, you need to create a listener. Check this website http://flash-creations.com/notes/asclass_key.php that is quite useful.


            Is it like a puzzle game you are doing?

            if your "places" are say a 10x10px square, on a line of 9 squares, i would create an array with 9 values, 0 being free, 1 occupied.


            placeArray = new Array(0,0,0,0,0,0,0,0,1);


            which means that the last square is occupied and all the others on the left are free.


            The way i'd do would be:

            state that your original object position is in square 9 (which is really the index 8 on the array, as the array index starts at 0)

            when the keylistener knows that the user presses the left arrow, check the value of placeArray[7], if it is 0, then move object._x -= 10.

            I then update the array so that placeArray[8] = 0 and placeArray[7] = 1.


            Hope this helps