(Translated) Mobile keyboard control

xiaoxiao2021-03-06  47

Mad SCI, in this tutorial, I mainly tell the keyboard event to trigger different move types, we will start from simple start, then complete some advanced coding technology, I assume that you are familiar with Flash5.0 (2K4 is also used) Scripting language, let us start from simple start .... Scene size is 300 * 300 Prepare an MC Putting Timeline OnClipevent (Enterframe) {if (Key.Isdown (Key.right)) THIS._X = 5; IF (Key.Indown) this._x- = 5; if (key.isdown (key.up)) this._y- = 5; if (Key.Indown (Key.Down) this._y = 5;} // This allows you to use it, down, left, right-click control movie MC ... // Note the coordinates in the upper left corner is (0, 0)! Let's do something change: OnClipEvent (Enterframe) {if (Key.Isdown (key.right)) this._x = 5; else if (key.Left) this._x- = 5; Else IF Key.IsDown (key.up)) this._y- = 5; else if (key.down (key.down)) this._y = 5;} // This is the only button, no two keys It is useful together. . . . We note that such a movie is 5 pixels / frame, so the frame rate is smoothed and fast! Let's change a little bit ... Let the program easier to expand, easier to change the speed! OnClipevent (LOAD) Step = 5; // Initialization Data Step ... OnClipevent (Enterframe) {IF (Key.Isdown (Key.Indown (key.Istown) )) this._x- = step; else if (key.up) this._y- = step; else if (Key.Isdown) this._y = step;} // So far, this is already better ... but the problem still exists, because the film can go outside the runway scene, this obvious we can't stand, how to change it? In fact, as long as you do a little change, you will line it, add a border judgment, you will line ... OnClipEvent (loading) {Step = 5;

Onclipevent (Enterframe) {IF (Key.IgH.Right && this._x <300) this._x = step; if (Key.Indown (Key.Left) && this._x> 0) this._x- = step; IF (Key.isdown && this._y> 0) this._y- = step; if (Key.ISDown (Key.Down) && this._y <300) this._y = step;} // you see If you don't understand, you can try to run these code! 2. There are two ways to move your movie. // Do a MOVIECLIP called SQR, the link attribute is set to the first, the title symbol is SQRONCLIPEVENT (LOAD)

{

Step = 5;

MoviewIDTH = 300;

MovieHeight = 300;

This.stop (); // Starting is empty, so that save memory resources

}

OnClipEvent (Enterframe)

{

Key.IndsDown && this._x

{

THIS.ATTachmovie ("SQR", "SQR1", 10);

THIS._X = STEP;

}

Else IF (Key.Ift) && this._x> 0) this._x- = step;

Else IF (Key.IP) && this._y> 0) this._y- = step;

Else IF (Key.ISDown) && this._y

} // If we have to press the left button, there is a film attached to this. This.attachimovie ("Run_LEFT", "Run", 10) this.attachimovie ("Run_Right", "Run", 10) this.attachimovie ("run_UP", "Run", 10) this.attachimovie ("run_down", "run", 10) // pay attention to the same depth, in this case, the previous film will be automatically met ... // can also this.Run .removemovieclip () this.attachmovie ("Run_left", 11);

转载请注明原文地址:https://www.9cbs.com/read-86458.html

New Post(0)