Flash Professional 8 - How to Add the Users Control to the Game
Video Transcript
Now, let us just get rid of our preview window and we will see about adding the user control to our game. Now, we want to set things up so our user can start interacting with the game as we have it right now. What we want to do is we want to have them take this pin object and of course, run around and pop a whole bunch of different bubbles. To start out that mechanism, we need to see how our movie clips are going to interact with each other. Now, I am going to setup a layer and let us bring our pin object onto the screen. I will put it right down here above the display or add a layer for our pin. And we will bring it out onto the stage and I will set it right here in the middle of the field some place. And of course, we are going to need to have it named so we can access it with action script as well. We will call it MC pin.
I might as well pull this bubble off stage because this is our starting bubble. It does not have to be actually seen on screen but it is needed in some place out here so we can duplicate the rest of our movie clips to it. Now, in older systems and older programs, we use to actually check interaction on screen by measuring a whole bunch of different X and Y coordinates. But the way flash deals with this subject is it actually allows us to take the boundary of the object that we are working with and test to see if it collides or touches or hits in any way any of the other objects. Now, we are talking about the boundary so it is really just the graphic itself that we are seeing inside of here and we are going to check that hitting or collision through the means of another method of movie clips called hit test.
Now, I would like to setup a little scenario here so we can try out hit test and see how it is going to be working. So, I am going to leave the pin the middle of the screen. We have got it named and we go back to our action script. Now, let us see if we can do a hit test for each one of the bubbles. In general, it does not matter where you check your hit test from. We can check it from the pin or we can check it from the bubble side of things.
Now, in our case, since have already got an init object for the bubble, it makes sense to go ahead and set it up on this side and we can build it right on to the init object along this all of this other statements that we have already setup. I will just scroll down to the bottom of our on enter frame handler and let us add one more little test. Now, ones again I am going to need an If statement because we are going to check to see if the bubble has actually collided or touched the pin in any way. I will start up my If statement. And for the condition, I am going to make use of our hit test method. We will use this keyword indicating the bubble that we are working on and it will call out the hit test method with a perimeter. Now, there is a whole bunch of perimeters showing up in how we are going to be handling a hit test. See if we got a simpler one here.
Going to the second one, you can see that we could test it against specific X and Y coordinates in the program but going to the third one that is one we are going to be using. We can check the hit test against the specific target. Now, as the target element, we can choose any other named element in our application and we are going to use the pin for that. So, I am going to test this against hitting MC pin.
Need to close up the parenthesis on the If statement so we finish our condition out and of course, we are going to need to open up some braces for our statements inside of our condition. I will just do a trace so we can see how it is working.
I will put some statement in here "hit the pin" and let us test our movie if we can see a bubble to run into it. Alright, I just left the pin kind to hang out at the middle of the screen so, we will just generate some bubbles and see if we can get one that is going to the direction of the pin. Here is one that it looks like it will hit. Looks like it faded first, there we go. Alright, I am going to stop my movie now just so we can go back and take a look at the outpu
Now, let us just get rid of our preview window and we will see about adding the user control to our game. Now, we want to set things up so our user can start interacting with the game as we have it right now. What we want to do is...
click to read more