Subscribe to our newsletter:
Page 1
This has been requested by a few people so I thought I will write it. In this tutorial you will learn how to make a scrolling background. I am using Macromedia/Adobe Flash 8 but Flash MX 2004 will work as well. It would help if you knew some basic actionscript since I am not going to go as in depth with the code as I usually might since this is alot like a few of the other tutorials.
Click here to see an example of what we will be making. Arrow Keys to move.
First of all open flash and draw the ground that you want to scroll and the character that will be walking. Make them each MC's (MovieClips). Give the ground an instance name of 'ground' and the character an instance name of 'man'.
Make sure the mans registration point is in the top left corner. Now paste this code on the frame.
The first line means "When this frame is entered". The second line is an if statement, checking if the left side of the square is not hitting the ground, if the statement is false flash will do nothing. If it is true, flash will make the ground move right, so it appears that the man is moving left. The 3rd line is checking if the Left arrow key is down, and the 4th is making the ground move left (like I just said) if the 3rd line is true.
Lines 7-9 are exactly the same as the previous ones except checking if the right side is hitting the ground and making the ground move left.
Now if you test your movie you should have a scrolling background when you move left or right. But if your MC hits a wall in the background it will stop scrolling.
Click here to see an example of what we will be making. Arrow Keys to move.
First of all open flash and draw the ground that you want to scroll and the character that will be walking. Make them each MC's (MovieClips). Give the ground an instance name of 'ground' and the character an instance name of 'man'.
Make sure the mans registration point is in the top left corner. Now paste this code on the frame.
onEnterFrame = function () {
if (!_root.ground.hitTest(_root.man._x, _root.man._y+(man._height/2), true)) {
if (Key.isDown(Key.LEFT)) {
_root.ground._x += 3;
}
}
if (!_root.ground.hitTest(_root.man._x+man._width, _root.man._y+(man._height/2), true)) {
if (Key.isDown(Key.RIGHT)) {
_root.ground._x -= 3;
}
}
};Lines 7-9 are exactly the same as the previous ones except checking if the right side is hitting the ground and making the ground move left.
Now if you test your movie you should have a scrolling background when you move left or right. But if your MC hits a wall in the background it will stop scrolling.





help
and feedback
latest
news
latest
forum entries