Ping Pong - Pause and Scrolling Text
| Category | : Flash | Views | : 22509 | ||
| Version | : 8 | Rating | : | ||
| Type | : Text | Source File | : ping-pong-pause-scrolling-text.zip | ||
| Result | : See the result | ||||
| <<< Previous | Index Series | Next >>> |
In the tutorial we are going to make the game to pause and display a scrolling text to alert the player that he need to press "P" to continue.
Let's start by making the Movie Clip where the text will scroll. Create a new Movie Clip, like it with the identifier "Scroll".
First thing you need to do is create a mask; a mask represents what is visible inside a Movie Clip. So only what's behind the mask will be seen.

The square can have any color and size you want.
Now in a new layer write the text that will be scrolling:

Use static text as we won't be changing in the code.
They should look like this on the first frame:

Right click the layer of the mask and select "Mask" then drag the text layer below the mask.

The rest is very simple, just a motion tween. Create a new keyframe on the 90 frame of both layers and on this new frame drag the text to the other side of the mask.

Right click the frames between the first and the last frame of layer 2 and select "Create Motion Tween". Flash will automatically create two files on your library, "Tween 1" and "Tween 2", because text can't be use directly in a tween animation.
Now go back the main timeline and paste this code:
//variable to see if the game is paused or not
var gpause = false;
//to know whether the pause key is being pressed or not
var keyHold = false;
this.onEnterFrame = function()
{
//if the "p"(code 80 in ascii) is pressed but not holded.
if ((Key.isDown(80)) && (!keyHold))
{
//set gpause to the contrary of it self
gpause = !gpause;
//if paused attach the scrolling text at the middle of the screen
if(gpause)
{
_root.attachMovie("Scroll", "Scroll", 10, {_x: 100, _y: 150});
}
//if not paused remove the "Scroll" Movie Clip
else
{
_root.Scroll.removeMovieClip();
}
//the p key is pressed
keyHold = true;
}
//if the "p" key(80) is not being pressed
else if (!Key.isDown(80))
{
//then keyPressed is false.
keyHold = false;
}
}
![]() |
![]() |
![]() |
![]() |
![]() |
| <<< Previous | Index Series | Next >>> |






