Forum Topic: AS: Scrolling Object

(3,948 views • 13 replies)

This topic is 1 page long.

<< < > >>
Shouting

lan00

Reply To Post Reply & Quote

Posted at: 10/1/05 03:45 AM

lan00 EVIL LEVEL 07

Sign-Up: 05/20/05

Posts: 217

======
INTRO
======
This is really a simple tut for all what it does is create a object that moves from one side of the screen to the other and when it gets tho the other side it appeas in a random spot on the other side. For example in This Game the scrolling koopas move from the left to right EASY
Please Note that all this script is designed to a 550 X 400 flash movie
Please E-Mail Me for any questions or post here.

http://flash-fantasy.com
=========
Let's Do It
=========
1. Create a new Flash Document (550 X 400)
2.Insert a new MC and call it bad
-- In that MC draw a simple circle
3. Now go back to the main scene and open the library (CTRL + L) and drag the bad MC onto the main scene
4.Open the actions panel (F9) and add these actions :

onClipEvent (load) {
this._x += 10;
if (this._x >= 560) {
this._x = 0
}
}

INFO
onClipEvent(load) means when the flash player loads the movie
this._x += 10; Means that the Bad MC increases then X axis by 10 each thime thus making it move across the screen
if (this._x >= 560) Means if the Bad MC is greater than or equal to 560 in the X axis...
this._x = 0 Place the Bad MC 0 in the X axis

5.Now push CTRL + ENTER and see if the Bad MC moves across the screen.
================
CONGRATULATIONS
================
You now have a perfectly good moving enemy for a shooting game.

Additinal Info
Ok there is still a few things to tell ya before i go so read...

1. Up And Down
Ok so you have a enemy going form left to right well maby you want it to go from top to bottom well its easy change the "this._x" to "this._y" and "if (this._x >= 560)" to "if (this._y >= 410)" easy
eg.

onClipEvent (load) {
this._y += 10;
if (this._y >= 410) {
this._y = 0
}
}

And Also if you want it to go from "down to up" or "right to left" just make the "this._y += 10;" to "this._y += -10;"
In other words make the speed to a negative so it moves backwards
But by reversing the way it moves you will have to change the actions as well:

eg.
onClipEvent (load) {
this._y += -10;
if (this._y >= -10) {
this._y = 0
}
}

And Thats All Folks
ENJOY...


None

Toast

Reply To Post Reply & Quote

Posted at: 10/1/05 04:28 AM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,914

Quite well detailed and explained.
I'd change
onClipEvent (load) {
this._x += 10;
if (this._x >= 560) {
this._x = 0
}
}

To
onClipEvent (load) {
this._x += 10;
if (this._x + (this._xscale / 2) >= 550) {
this._x = 0
}
}

Otherwise it's really nice.


None

lan00

Reply To Post Reply & Quote

Posted at: 10/1/05 04:39 AM

lan00 EVIL LEVEL 07

Sign-Up: 05/20/05

Posts: 217

well ether way it still works


Happy

Flashdavis

Reply To Post Reply & Quote

Posted at: 10/1/05 04:42 AM

Flashdavis LIGHT LEVEL 08

Sign-Up: 09/15/05

Posts: 193

cheers


None

Toast

Reply To Post Reply & Quote

Posted at: 10/1/05 04:44 AM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,914

At 10/1/05 04:39 AM, lan00 wrote: well ether way it still works

Nope, your code works well only for 20 width movieClips...


None

lan00

Reply To Post Reply & Quote

Posted at: 10/1/05 04:46 AM

lan00 EVIL LEVEL 07

Sign-Up: 05/20/05

Posts: 217

well sorry to start a argument here but i used that in my flash game kill the koopas and the width of the koopa is 41.3


None

Toast

Reply To Post Reply & Quote

Posted at: 10/1/05 04:48 AM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,914

Then it either went to 0_x at a higher _x than 550 or lower...


None

lan00

Reply To Post Reply & Quote

Posted at: 10/1/05 04:49 AM

lan00 EVIL LEVEL 07

Sign-Up: 05/20/05

Posts: 217

oh well who cares not me....


Angry

Toast

Reply To Post Reply & Quote

Posted at: 10/1/05 04:51 AM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,914

I CARE >:(

coz if u so teh 1337 width is suxxors >:(


None

Rustygames

Reply To Post Reply & Quote

Posted at: 10/1/05 04:59 AM

Rustygames LIGHT LEVEL 18

Sign-Up: 05/07/05

Posts: 6,662

Why do you keep making these n00by tutorials

- Matt, Rustyarcade.com


None

lan00

Reply To Post Reply & Quote

Posted at: 10/1/05 05:32 AM

lan00 EVIL LEVEL 07

Sign-Up: 05/20/05

Posts: 217

its not a nOOby Tutorial


None

MilkshakeClock

Reply To Post Reply & Quote

Posted at: 10/1/05 05:35 AM

MilkshakeClock LIGHT LEVEL 17

Sign-Up: 01/21/04

Posts: 197

Better code:

This was all made for an overhead scrolling game so you might need to edit if you have a side scroller.

onClipEvent (load) {
function reset() { //makes a function which controls this object's movement
this._y = -50; //makes the units y position -50, which is off the stage
this._x = random(550); //gives the unit a random x position of 550 pixels (change the number to the width of your stage)
thisSpeed = 17+random(10); //make the object a speed of at least 17 or a max of 26 (random speed)
}
reset(); //does it to get the game started
}
onClipEvent (enterFrame) {
if (this._y>=1900) {
reset(); /calls our function when the y pos is 1900, you could change this. I like to have it like that so it gives it a random feel. If you want the object to occour less times, set this number higher.
}
if (hitTest(_root.bullet) == true) {
//whatever you want it to do when it hits the bullet etc.
this._y = 800; //you could call the reset function here if you want but i like to just throw it off stage to give it a more of a random feel
}
}
onClipEvent (enterFrame) {
this._y += thisSpeed; //makes the object move, the speed set by our reset function.
}


None

salted-tator-tot

Reply To Post Reply & Quote

Posted at: 6/5/06 07:04 PM

salted-tator-tot FAB LEVEL 30

Sign-Up: 02/26/06

Posts: 3,316

onClipEvent (enterFrame) {
if (this.hitTest(_root.playa)) {
gotoAndPlay(2);
}
}

what is wrong? my guy (playa) keeps hitting the wall (wall(even though it is 'this'))

01000100011000010110111001100011011 01001011011100110011101010000011010 01011011100110010101100001011100000 11100000110110001100101010001110111 010101111001

BBS Signature

Questioning

KobyMcSlick

Reply To Post Reply & Quote

Posted at: 12/13/07 12:21 PM

KobyMcSlick NEUTRAL LEVEL 07

Sign-Up: 07/11/01

Posts: 57

Do you think its better to scroll a whole group of enemies using an array and the for loop or by putting all the enemies in a movie clip and scrolling that?


All times are Eastern Standard Time (GMT -5) | Current Time: 07:38 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!