Be a Supporter!

AS: Scrolling Background

  • 11,782 Views
  • 54 Replies
New Topic Respond to this Topic
DrDeath2k3
DrDeath2k3
  • Member since: Sep. 4, 2003
  • Offline.
Forum Stats
Member
Level 28
Blank Slate
AS: Scrolling Background 2005-06-28 15:13:26 Reply

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

Xentron
Xentron
  • Member since: Mar. 5, 2005
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to AS: Scrolling Background 2005-06-28 15:17:19 Reply

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

Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AS: Scrolling Background 2005-06-28 15:23:39 Reply

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;
}
}

DrDeath2k3
DrDeath2k3
  • Member since: Sep. 4, 2003
  • Offline.
Forum Stats
Member
Level 28
Blank Slate
Response to AS: Scrolling Background 2005-06-28 15:28:26 Reply

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.

Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AS: Scrolling Background 2005-06-28 15:30:41 Reply

my msn is benjamingr@msn.com ring me

Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to AS: Scrolling Background 2005-06-28 15:32:38 Reply

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
Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AS: Scrolling Background 2005-06-28 15:36:13 Reply

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 ;)

T-H
T-H
  • Member since: Jan. 7, 2004
  • Offline.
Forum Stats
Member
Level 40
Blank Slate
Response to AS: Scrolling Background 2005-06-28 15:43:35 Reply

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!))

Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to AS: Scrolling Background 2005-06-28 15:44:46 Reply

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
Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AS: Scrolling Background 2005-06-28 15:46:50 Reply

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 ;)

Kipling
Kipling
  • Member since: May. 4, 2004
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
Response to AS: Scrolling Background 2005-07-24 08:51:03 Reply

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

Dipshitprod
Dipshitprod
  • Member since: Mar. 13, 2005
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to AS: Scrolling Background 2005-10-08 08:24:38 Reply

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 =/

Devenger
Devenger
  • Member since: Dec. 24, 2004
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to AS: Scrolling Background 2005-10-08 09:11:32 Reply

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.

alexhall
alexhall
  • Member since: Jul. 25, 2004
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to AS: Scrolling Background 2005-11-04 11:18:51 Reply

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

rmthegreat88
rmthegreat88
  • Member since: Apr. 17, 2004
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to AS: Scrolling Background 2005-11-04 11:22:15 Reply

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

Claxor
Claxor
  • Member since: Oct. 21, 2005
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to AS: Scrolling Background 2005-11-04 11:42:02 Reply

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

Thats also a way to do it.


BBS Signature
neowolf22964
neowolf22964
  • Member since: May. 1, 2004
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to AS: Scrolling Background 2005-11-06 11:10:10 Reply

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?

HPen
HPen
  • Member since: Nov. 15, 2005
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to AS: Scrolling Background 2005-11-15 15:03:47 Reply

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

Vengeance
Vengeance
  • Member since: Mar. 18, 2005
  • Offline.
Forum Stats
Member
Level 28
Blank Slate
Response to AS: Scrolling Background 2005-11-15 15:12:25 Reply

wtf do you mean, use proper punctuation


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

BBS Signature
HPen
HPen
  • Member since: Nov. 15, 2005
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to AS: Scrolling Background 2005-11-15 15:14:02 Reply

wtf do you mean with that proper punctuation

Vengeance
Vengeance
  • Member since: Mar. 18, 2005
  • Offline.
Forum Stats
Member
Level 28
Blank Slate
Response to AS: Scrolling Background 2005-11-15 15:24:40 Reply

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
liam
liam
  • Member since: Dec. 11, 2004
  • Offline.
Forum Stats
Member
Level 22
Blank Slate
Response to AS: Scrolling Background 2005-11-15 15:27:51 Reply

Something easay:

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


Sup, bitches :)

BBS Signature
spawn28
spawn28
  • Member since: Mar. 15, 2004
  • Offline.
Forum Stats
Member
Level 14
Blank Slate
Response to AS: Scrolling Background 2005-11-15 17:17:31 Reply

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.

spawn28
spawn28
  • Member since: Mar. 15, 2004
  • Offline.
Forum Stats
Member
Level 14
Blank Slate
Response to AS: Scrolling Background 2005-11-15 17:23:15 Reply

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.

DemitriW
DemitriW
  • Member since: Oct. 9, 2005
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to AS: Scrolling Background 2005-11-26 07:27:46 Reply

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

Chris
Chris
  • Member since: Sep. 17, 2004
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to AS: Scrolling Background 2005-12-03 09:04:32 Reply

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.

kitsunez
kitsunez
  • Member since: Jul. 31, 2003
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to AS: Scrolling Background 2005-12-20 17:29:18 Reply

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

icarus
icarus
  • Member since: Jan. 10, 2005
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
Response to AS: Scrolling Background 2005-12-29 05:02:12 Reply

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.

TrueDarkness
TrueDarkness
  • Member since: Aug. 31, 2004
  • Offline.
Forum Stats
Member
Level 27
Blank Slate
Response to AS: Scrolling Background 2005-12-29 11:04:26 Reply

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 :)

aquaticmole
aquaticmole
  • Member since: Feb. 10, 2005
  • Offline.
Forum Stats
Member
Level 29
Melancholy
Response to AS: Scrolling Background 2006-02-05 11:35:53 Reply

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