PDA

View Full Version : Scrolling



Capt. Ninja
November 2nd, 2006, 12:23 AM
I'm a newb when it comes to actionscript, so I dont know how to make the background/stage scroll, or follow your moving character. How would one go about doing this?

SacrificialLamb
November 2nd, 2006, 12:35 AM
if you put every thing on the background in one mc with instance name on "bg" and add thins code to a frame in your mane time line

speed=10
onEnterFrame = function () {
if (Key.isDown(Key.LEFT)) {
_root.bg._x += speed;
}
if (Key.isDown(Key.RIGHT)) {
_root.bg._x -= speed;
}
if (Key.isDown(Key.UP)) {
_root.bg._y += speed;
}
if (Key.isDown(Key.DOWN)) {
_root.bg._y -= speed;
}
}

Capt. Ninja
November 2nd, 2006, 12:51 AM
Well, that did suit my needs, but what if the background was very large? Wouldn't constantly moving a huge background be really inefficient? Instead, how could I move the so called view you see of the stage, while the background stays still?

SacrificialLamb
November 2nd, 2006, 01:29 AM
do you really think for the computer that it will know the difference? I don’t think it would... but I don’t really know so, this will move every thing on the stage except "char"

speed=10
onEnterFrame = function () {
if (Key.isDown(Key.LEFT)) {
_x += speed;
_root.char._x-= speed;
}
if (Key.isDown(Key.RIGHT)) {
_x -= speed;
_root.char._x+= speed;
}
if (Key.isDown(Key.UP)) {
_y += speed;
_root.char._y-= speed;
}
if (Key.isDown(Key.DOWN)) {
_y -= speed;
_root.char._y+= speed;
}
}

Capt. Ninja
November 2nd, 2006, 01:41 AM
Alright, you got it doing what I wanted, so thanks for the help.