00:00
00:00
Newgrounds Background Image Theme

SourJovis just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

AS: Scrolling Background

14,720 Views | 51 Replies
New Topic Respond to this Topic

AS: Scrolling Background 2005-06-28 15:13:26


This is something I am currently using in a game I am making.
(If you can help with some AS, please respond with your e-mail)

Ok, this is quite easy.

First, draw the background you want to scroll. Make sure it is very long or high, depending on the type of game.

Make the background a movieclip. (duh!)

Highlight it and go to it's action panel. (F9)

Put in this actionscript!

onClipEvent (enterFrame) {
// When the right key is down, it starts scrolling left.
if(Key.isDown(Key.RIGHT)) {
this._x=_x-10;
}
}
onClipEvent (enterFrame) {
// When the left key is down, it starts scrolling right.
if(Key.isDown(Key.LEFT)) {
this._x=_x+10;
}
}

//You can change the speed (the 10) to whatever you want.

Ok, if you want it to scroll up / down, simply change the Left / Right to Up / Down and the x's to y's.

This can be used in many types of games.

If you have any questions, just respond! = D

Response to AS: Scrolling Background 2005-06-28 15:17:19


If you need any help, my email is xentron@gmail.com

Response to AS: Scrolling Background 2005-06-28 15:23:39


THIS IS NOT THE EASY WAY TO DO BACKGROUND SCROLLING

you'll have a shitty time hitTesting it(the player) against stuff inside the background, you need to put the player inside the background if you want hitTests to work right

the easy way (for me at least) is to use a Scripted camera, instead of moving the "background" you move the camera and the player, it's easy, and simple

if you insist on not doing so, move the palyer and the background, that would work too...

trust me, I have some exp on this, scrollng only the BG is a pain in the ass... sorry for being so sure of my way being right :P I just had some painful experiance :(

on the player

onClipEvent(enterFrame){
if(Key.isDown(Key.RIGHT)){
this._x+=5;
_parent._x-=5;
}else if(Key.isDown(Key.LEFT)){
this._x-=5;
_parent._x+=5;
}else if(Key.isDown(Key.UP)){
this._y-=5;
_parent._y+=5;
}else if(Key.isDown(Key.DOWN)){
this._y+=5;
_parent._y-=5;
}else if(Key.isDown(Key.RIGHT)){
this._x+=5;
_parent._x-=5;
}
}

Response to AS: Scrolling Background 2005-06-28 15:28:26


At 6/28/05 03:23 PM, Inglor wrote: BLEH

If you have MSN, I added you. I can send you the file and you can see how awesomeness it is.

...And I could use some help on it.

Response to AS: Scrolling Background 2005-06-28 15:30:41


my msn is benjamingr@msn.com ring me

Response to AS: Scrolling Background 2005-06-28 15:32:38


At 6/28/05 03:23 PM, Inglor wrote: on the player

onClipEvent(enterFrame){
if(Key.isDown(Key.RIGHT)){
this._x+=5;
_parent._x-=5;
}else if(Key.isDown(Key.LEFT)){
this._x-=5;
_parent._x+=5;
}else if(Key.isDown(Key.UP)){
this._y-=5;
_parent._y+=5;
}else if(Key.isDown(Key.DOWN)){
this._y+=5;
_parent._y-=5;
}else if(Key.isDown(Key.RIGHT)){
this._x+=5;
_parent._x-=5;
}
}

or using binary:

onClipEvent(load){spd=5;}
onClipEvent(enterFrame) {
_x-=Key.isDown(37)*spd;
_x+=Key.isDown(39)*spd;
_y-=Key.isDown(38)*spd;
_y+=Key.isDown(40)*spd;
_parent._x+=Key.isDown(37)*spd;
_parent._x-=Key.isDown(39)*spd;
_parent._y+-=Key.isDown(38)*spd;
_parent._y-=Key.isDown(40)*spd;
}


- - Flash - Music - Images - -

BBS Signature

Response to AS: Scrolling Background 2005-06-28 15:36:13


I appreciate you paying attention to my binary tutorial :P (I know you probebly knew that before)

but using binary isn't a good idea since you can't do 'else if' with binary

and if you wanna do it binary, at least do it

_x+=(Key.isDown(Key.RIGHT)*spd+(Key.isDown(Key.LEFT)*(-spd);

it's even shorter ;)

Response to AS: Scrolling Background 2005-06-28 15:43:35


This is the second shitty attempt at an AS: reference topic today, inglor and Denvish had to come along and salvage it. Don't make tutorials about obvious stuff (in this case shifting the bg using _x- / _x+. (OMFG liek, that so clever!11!))

Response to AS: Scrolling Background 2005-06-28 15:44:46


The thing is, with that code, you don't need any else if's. In fact, I think it's better since it allows diagonal movement as well, with no key clashes. I understand what you're saying, though.


- - Flash - Music - Images - -

BBS Signature

Response to AS: Scrolling Background 2005-06-28 15:46:50


fine so I remove one 'else' and I don't have any key clashes either :P I still get 3/4 of the average runspeed ;)

Response to AS: Scrolling Background 2005-07-24 08:51:03


At 6/28/05 03:17 PM, Xentron wrote: If you need any help, my email is xentron@gmail.com

I'll keep that in mind next time I want your help. lol

Response to AS: Scrolling Background 2005-10-08 08:24:38


At 6/28/05 03:43 PM, T-H wrote: This is the second shitty attempt at an AS: reference topic today, inglor and Denvish had to come along and salvage it. Don't make tutorials about obvious stuff (in this case shifting the bg using _x- / _x+. (OMFG liek, that so clever!11!))

Well, there are people who don't know stuff (the easy or hard way), and that's why forums like these exist..... also, Some improvements or easier ways are supposed to be written here, if you meant the opposite, yesterday I fixed a flaw on the basic movement AS =).... so.... don't just say something is a shitty attempt if you only know half the reason for it =/

Response to AS: Scrolling Background 2005-10-08 09:11:32


Still, it's not a good idea to write an AS: unless it's pretty advanced, because all the simple stuff has been donezor'd. Maybe I'm utterly wrong, and Inglor will have to flame me for another page though. *yawn*

Instant newb satisfaction: play with _root._x and _root._y. :D I'll just leave now.


I'm back! on a temporary basis. No-one can remember who I am! but I don't really mind.

Response to AS: Scrolling Background 2005-11-04 11:18:51


how do i get it to stop scroling when it is at the end?

Response to AS: Scrolling Background 2005-11-04 11:22:15


At 11/4/05 11:18 AM, papperboy wrote: how do i get it to stop scroling when it is at the end?

put like an ending wall there and once the hero runs into it, go to a new frame.

kinda like a mario game

Response to AS: Scrolling Background 2005-11-04 11:42:02


At 6/28/05 03:32 PM, Denvish wrote: binary stuff

Thats also a way to do it.


BBS Signature

Response to AS: Scrolling Background 2005-11-06 11:10:10


Yep that is the right way to do it.
Could you tell me how to do that but at the same time Making the charecters legs move and Wot ever?

Response to AS: Scrolling Background 2005-11-15 15:03:47


okay.... but if the map/world is moving how do you made that if the car hittest a bounce the maps speed = -20?

Response to AS: Scrolling Background 2005-11-15 15:12:25


wtf do you mean, use proper punctuation


========|| WWWWWWWW>[-[Blog] - [Audio] - [Userpage] - [Flash] - [Last.fm]-]<WWWWWWWW ||========

BBS Signature

Response to AS: Scrolling Background 2005-11-15 15:14:02


wtf do you mean with that proper punctuation

Response to AS: Scrolling Background 2005-11-15 15:24:40


At 11/15/05 03:03 PM, HPen wrote: okay.... but if the map/world is moving how do you made that if the car hittest a bounce the maps speed = -20?

well, i re-read it (im tired at the moment its 6:00AM and i just woke up) and sorry for the punctuation comment.
put this in the car MC.
onClipEvent(enterFrame){
if(this.hitTest(_root.bumpMC)){
_root.car.mapspeed-=20 //change _root.car.mapspeed to whatever variable its saved to and the source thats its saved to.
}}


========|| WWWWWWWW>[-[Blog] - [Audio] - [Userpage] - [Flash] - [Last.fm]-]<WWWWWWWW ||========

BBS Signature

Response to AS: Scrolling Background 2005-11-15 15:27:51


Something easay:

onMouseMove=function(){
xspd = (_xmouse-x1), yspd = (_ymouse-y1);
_x+=xspd, _y+=yspd;
x1=_xmouse,y1=_ymouse;
}


Sup, bitches :)

BBS Signature

Response to AS: Scrolling Background 2005-11-15 17:17:31


lol, this is not hard to do, what is hard is to get the bg to only move when your character is at the edge of the screen, and then the bg moves... and the bg stops at end of the screen..... so that the screen doesnt go blank and that the bg doesnt go off screen. i will upload my current file to uhhh image shack and show u what i mean.

Response to AS: Scrolling Background 2005-11-15 17:23:15


okay heres a really complicated scrolling bg and moving character.
http://img490.images..ge=narutogame0mq.swf

ignore the thing saying read this AS, as it is just a note to self.
this consists of a charater (idle, and walking animations),
4 invisible boxes that are their to tell the script when to stop the bg and crap.
1 bg.
and 150+ lines of code just in that.

Response to AS: Scrolling Background 2005-11-26 07:27:46


this is good but i want scrolling background for a movie not a game

Response to AS: Scrolling Background 2005-12-03 09:04:32


At 6/28/05 03:23 PM, Inglor wrote: on the player

onClipEvent(enterFrame){
if(Key.isDown(Key.RIGHT)){
this._x+=5;
_parent._x-=5;
}else if(Key.isDown(Key.LEFT)){
this._x-=5;
_parent._x+=5;
}else if(Key.isDown(Key.UP)){
this._y-=5;
_parent._y+=5;
}else if(Key.isDown(Key.DOWN)){
this._y+=5;
_parent._y-=5;
}else if(Key.isDown(Key.RIGHT)){
this._x+=5;
_parent._x-=5;
}
}

how would i reset the camera's position after this? you know so the camera doesn't stay over there when you goto a new frame.

Response to AS: Scrolling Background 2005-12-20 17:29:18


I'm full of questions......but anyways.....as i'm lookingto do a final fight type game I want to know if it is possible to have a background taht scrolls only after you completed an objective like defeat all the enemies on the screen and it's lock in place till when another objective came up....it's all kinda overwhelming for me but i'm trying

Response to AS: Scrolling Background 2005-12-29 05:02:12


I made a game where i needed scrolling, but i wanted the player to be centered when it was scrolling so all i did was once the players _x was >= 1/2screen width every time they moved _root._x += 1 and player._x -= 1.
This is also alot bettre i believe, because it moves evrything besides the player, like enemys, not just the background.

Response to AS: Scrolling Background 2005-12-29 11:04:26


I think it would be easiest if you were to make the background follow the player and scroll as it does. It's simple.
Give your character the scripts for him to move left and right and give him an instance name such as "player"
Then on the background just add a script like...
onClipevent(enterFrame){
this._x=_root.player._x/5
}

You can change /5 to any number that suits you and the game :)

Response to AS: Scrolling Background 2006-02-05 11:35:53


At 12/3/05 09:04 AM, IS_ChRiS wrote: how would i reset the camera's position after this? you know so the camera doesn't stay over there when you goto a new frame.

thats a question i thought about and tryed to solve but couldn't, could someone help us out?

Please?

aquaticmole.

BBS Signature