Movement in animation and games is often actually done with ActionScript because ActionScript allows for flexibility over the Timeline alone. I'm going to show you exactly what I'm talking about, because what I want to do is I want to animate this intro screen out.
In fact, I want it to move over to the left-hand side when you click on the Start button. I also want to do the same thing for this end screen. So again, I want to create some animation using ActionScript, and I want to animate both of these things here.
I'm going to start off by using some code snippets. So in the previous lesson, I talked about how to add to this Mobile Game folder, and I'm going to select Animate with ActionScript. And when I double-click on it, it will add that code to my Actions panel on that first frame right there, so I'll just double-click on it and it adds that code.
Okay, so the first thing I have here are the import statements, okay, so I need these import statements in order for this code to work down here,
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
because this code down here references these various classes, and that's what these are, classes and packages. So you can see TweenEvent. Well, I'm using that tween event right here.
var introTween = new Tween(screen,"x",Strong.easeInOut,screen.x,(screen.width)*-1,1,true);
function tweenFinish(e:TweenEvent):void
{
trace("tweenFinish");
}
So I need these three lines (the import statements) , so I will just take them three and I'll cut them and I'll scroll up to the top, because I want to make sure those import statements are at the top and the code is there before I start to actually use it, because this Flash ActionScript code executes from the top down.
So lets scroll down, and again down here at the bottom, I want to take this code
var introTween = new Tween(screen,"x",Strong.easeInOut,screen.x,(screen.width)*-1,1,true);
function tweenFinish(e:TweenEvent):void
{
trace("tweenFinish");
}
and I want to cut it as well and put it in the appropriate area.
in INTRO SCREEN area in function moveScreenOff see the next image
Again, right in here for this intro tween I have this introTween variable, and it creates this new tween. And the first thing you needed to do is define what will be animated, and in this case I wanted to be the introScreen. So the introScreen is actually a variable that gets passed in, and inside of this moveScreenOff, it's actually known as screen, so whatever gets passed into this function it references back to that name. So all I really need right in here is not introScreen.
I just need screen okay, because I'm going to use this movieScreenOff function a couple of times. So again screen refers to introScreen. It's going to move its X position. That could be Y position. It could be its size. It could be its alpha or its transparency, if you will. But I want to move it to the left and then right. Okay, so that's the property I'm going to move. This is how I'm going to move it, so it's going to move it sort of in a strong motion from the right to the left.
Okay, there's bounce. There is also elastic that I can use. Next step, right here this is its starting position, its ending position, and then numbers in seconds that that transition will take place. So that's how the tween class works, okay. And for it's start position, well, I don't want it to start at zero, because, quite frankly, the screen isn't at zero. I want it to start from wherever the screen is, so I can type in screen.x, so wherever it is, start there and then move it to, not to a thousand, because that's going to move it to the right, what I want to do is I want to take this right here.
I want to take what is the equivalent of minus 800, or whatever the size of that item is, and that's where I want the ending position to these. So I'll cut that and paste that right in there. In fact, I don't even need this line right there anymore. Okay, so its starting position is wherever it is. Its ending position is its width in a negative number. So that's what this does. It's going to happen over the course of one second. True means you're setting the interval to seconds okay, and what this means is it doesn't matter what the frames per second of the Timeline is.
Okay, so for the introTween right here, on motion_finish go ahead ahead fire off this function. Well, what do I want to happen during that time? Let me scroll down, because that's when I want to initialize the game, throw in a trace statement and add that intro frame. So I'll cut all of that code and move that right into that function right there. All right, so far so good. In fact, the last thing I'm going to do is I'm going hit this Auto Format button, just so it formats and indents all my code. I can see that this function is nice and neat now, and I'd say this is ready to go.
Okay, so again I've cleaned up this moveScreenOff function. So whether it's the introScreen or something else, it's going to animates it using this Tween class. But I'm using this moveScreenOff in another place. In fact, clear down at the bottom, right here, line 132, I'm calling that same moveScreenOff. And in this case it's going to move off the endScreen. And that's the power of ActionScript animation is here I'm able to also move the endScreen as well as the introScreen, all from within one function using the Tween class.
All right, so let just do a test movie. There it is. We see that Timeline animation. I'm going to click Play.
We'll see it slide off to the left, and again it goes through the game, and then we have this high score screen. If I click Play Again, it's going to animate this off the screen as well, just like that. So two animations done pretty easily by using the Tween class as well as the on- motion finish. It really gives me a nice effect, and it also makes it reusable.
to download the file click here
wait us in the next lesson ...
In fact, I want it to move over to the left-hand side when you click on the Start button. I also want to do the same thing for this end screen. So again, I want to create some animation using ActionScript, and I want to animate both of these things here.
I'm going to start off by using some code snippets. So in the previous lesson, I talked about how to add to this Mobile Game folder, and I'm going to select Animate with ActionScript. And when I double-click on it, it will add that code to my Actions panel on that first frame right there, so I'll just double-click on it and it adds that code.
Okay, so the first thing I have here are the import statements, okay, so I need these import statements in order for this code to work down here,
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
because this code down here references these various classes, and that's what these are, classes and packages. So you can see TweenEvent. Well, I'm using that tween event right here.
var introTween = new Tween(screen,"x",Strong.easeInOut,screen.x,(screen.width)*-1,1,true);
function tweenFinish(e:TweenEvent):void
{
trace("tweenFinish");
}
So I need these three lines (the import statements) , so I will just take them three and I'll cut them and I'll scroll up to the top, because I want to make sure those import statements are at the top and the code is there before I start to actually use it, because this Flash ActionScript code executes from the top down.
So lets scroll down, and again down here at the bottom, I want to take this code
var introTween = new Tween(screen,"x",Strong.easeInOut,screen.x,(screen.width)*-1,1,true);
function tweenFinish(e:TweenEvent):void
{
trace("tweenFinish");
}
and I want to cut it as well and put it in the appropriate area.
in INTRO SCREEN area in function moveScreenOff see the next image
Again, right in here for this intro tween I have this introTween variable, and it creates this new tween. And the first thing you needed to do is define what will be animated, and in this case I wanted to be the introScreen. So the introScreen is actually a variable that gets passed in, and inside of this moveScreenOff, it's actually known as screen, so whatever gets passed into this function it references back to that name. So all I really need right in here is not introScreen.
I just need screen okay, because I'm going to use this movieScreenOff function a couple of times. So again screen refers to introScreen. It's going to move its X position. That could be Y position. It could be its size. It could be its alpha or its transparency, if you will. But I want to move it to the left and then right. Okay, so that's the property I'm going to move. This is how I'm going to move it, so it's going to move it sort of in a strong motion from the right to the left.
Okay, there's bounce. There is also elastic that I can use. Next step, right here this is its starting position, its ending position, and then numbers in seconds that that transition will take place. So that's how the tween class works, okay. And for it's start position, well, I don't want it to start at zero, because, quite frankly, the screen isn't at zero. I want it to start from wherever the screen is, so I can type in screen.x, so wherever it is, start there and then move it to, not to a thousand, because that's going to move it to the right, what I want to do is I want to take this right here.
I want to take what is the equivalent of minus 800, or whatever the size of that item is, and that's where I want the ending position to these. So I'll cut that and paste that right in there. In fact, I don't even need this line right there anymore. Okay, so its starting position is wherever it is. Its ending position is its width in a negative number. So that's what this does. It's going to happen over the course of one second. True means you're setting the interval to seconds okay, and what this means is it doesn't matter what the frames per second of the Timeline is.
Okay, so for the introTween right here, on motion_finish go ahead ahead fire off this function. Well, what do I want to happen during that time? Let me scroll down, because that's when I want to initialize the game, throw in a trace statement and add that intro frame. So I'll cut all of that code and move that right into that function right there. All right, so far so good. In fact, the last thing I'm going to do is I'm going hit this Auto Format button, just so it formats and indents all my code. I can see that this function is nice and neat now, and I'd say this is ready to go.
Okay, so again I've cleaned up this moveScreenOff function. So whether it's the introScreen or something else, it's going to animates it using this Tween class. But I'm using this moveScreenOff in another place. In fact, clear down at the bottom, right here, line 132, I'm calling that same moveScreenOff. And in this case it's going to move off the endScreen. And that's the power of ActionScript animation is here I'm able to also move the endScreen as well as the introScreen, all from within one function using the Tween class.
All right, so let just do a test movie. There it is. We see that Timeline animation. I'm going to click Play.
We'll see it slide off to the left, and again it goes through the game, and then we have this high score screen. If I click Play Again, it's going to animate this off the screen as well, just like that. So two animations done pretty easily by using the Tween class as well as the on- motion finish. It really gives me a nice effect, and it also makes it reusable.
to download the file click here
wait us in the next lesson ...
0 التعليقات:
Post a Comment