Ultimate Gear War
Join the alien war, prepare your gear and protect your base at all cost!
4.15 / 5.00 16,770 ViewsThis 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
If you need any help, my email is xentron@gmail.com
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;
}
}
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.
my msn is benjamingr@msn.com ring me
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;
}
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 ;)
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!))
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.
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 ;)
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
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 =/
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.
how do i get it to stop scroling when it is at the end?
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
At 6/28/05 03:32 PM, Denvish wrote: binary stuff
Thats also a way to do it.
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?
okay.... but if the map/world is moving how do you made that if the car hittest a bounce the maps speed = -20?
wtf do you mean, use proper punctuation
wtf do you mean with that proper punctuation
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.
}}
Something easay:
onMouseMove=function(){
xspd = (_xmouse-x1), yspd = (_ymouse-y1);
_x+=xspd, _y+=yspd;
x1=_xmouse,y1=_ymouse;
}
Sup, bitches :)
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.
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.
this is good but i want scrolling background for a movie not a game
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.
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
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.
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 :)
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.