Ping Pong - Moving Pads
| Category | : Flash | Views | : 21797 | ||
| Version | : 8 | Rating | : | ||
| Type | : Text | Source File | : ping-pong-moving-pads.zip | ||
| Result | : See the result | ||||
| <<< Previous | Index Series | Next >>> |
I didn't move my pad and these are the scores I got:

Code Explanation
onClipEvent(enterFrame)
{
if(Key.isDown(Key.RIGHT))
{
point = new Object();
point.x = this._x;
point.y = this._y;
localToGlobal(point);
This piece of code creates a point object with the properties "x" and "y" equal to the Movie Clip's _x and _y properties.Then we translate this local (inside the parent Movie Clip) coordinate to a global (stage) coordinate using the function:
localToGlobal(point object);
The function won't return a value but will convert the point object you passed to it.
if(point.x + 10 >= 220)
{
return;
}
If the point object we just created plus the moving speed is greater that what this Movie Clip can move (220px) we return and the next line of code won't run.
this._x += 10;
}
else if(Key.isDown(Key.LEFT))
{
point = new Object();
point.x = this._x;
point.y = this._y;
localToGlobal(point);
if(point.x - 10 <= -20)
{
return;
}
If the global _x coordinate of this Movie Clip (point.x) is smaller than what it can move to the left, return.
this._x -= 10;
}
}
In the next tutorial we are going to make scores and the game more difficult.
More cool tech articles from other blogs.
| <<< Previous | Index Series | Next >>> |
