2 Replies Latest reply on May 28, 2011 11:57 AM by AngelMichu

    Snapping Objects together

    AngelMichu Level 1

      Hello, I have 2 issues.


      The first one is, i haven't figured out how to make 2 square objects snap together, side by side.. let me explain..


      All of this is for a game with 8 square pieces. The idea is that when one piece is relatively close to the piece it should go next to, it would snap together and therefore, those 2 pieces would become 1 movable object, and so on with the rest of the pieces, until all 8 pieces are put together into 1 movable object.


      I've been searching for a code for this and havent really found one yet .



      The second issue that i have, is: how can i tell flash that when all those 8 pieces are put together in the right places, the player has "won" and therefore it needs to show the winning screen (which is on a different frame)?



      So far, what i've managed is to set up the drag code to all the pieces, a timer and a start and a reset button..



      Oh one more thing, in that winning screen, how can i show the time it took that person to win?

        • 1. Re: Snapping Objects together
          prodigalmaster Level 2

          Try reading tutorials on these types of things, I can't just code a game for you for free.


          I will still try to help. I am assuming you use Actionscript2. You should try to always only use the main timeline for actionscript.


          "The first one..."

          Search/Google for:

          hitTest tutorials, MovieClip and instances tutorials.


          "The second issue..."

          Search/Google for:

          variable tutorials, if statements.


          Here is some help, copy and paste it into flash to see syntax highlighting. // = comment


          var won:Boolean = false; 
          //var is variable, won is the name you give it to refer to for later use, 
          //:Boolean is not needed but it is good for optimisation, it gives the var only 2 values; true and false.
          // = false this gives the var the value of false
          // ; this ends the line of code.
          onEnterFrame = function(){
          if(won == true){
          // onEnterFrame = function() {...} this means it executes(does) the code inside the {} brackets at the speed of the FPS (12 fps means 12 times a second)
          //if(won == true){...} this is an 'if' statement which executes the code inside the {} brackets if won is equal to true.
          // remember do not do: won = true because that assigns the value true to won instead.
          //gotoAndStop("winFrame"); this means move the frame to "winFrame". You have to name a frame winFrame by clicking the correct frame in the timeline and //going to properties then under frame: <frame label> type winFrame.
          //you could add the frame number instead of "winFrame" but it may be easier the other way if you change the position of frames in the future.


          I hope this has helped!


          Oh and in the winning screen just add a DYNAMIC text box using the text tool and changing in the properties from static to dynamic. Then at the bottom right of the properties inspector there will be: var with a text box type the variable used for the timer.

          1 person found this helpful
          • 2. Re: Snapping Objects together
            AngelMichu Level 1

            Thanks a lot this is very helpful!! I will try this out. And dont worry.. I understand that you cant give me the whole thing for free... im just in the process of learning AS and I just have no idea how to do those things yet, and was having trouble finding how to do it.


            And yes.. im using AS 2.