00:00
00:00
Newgrounds Background Image Theme

Arnahan 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 Object

5,946 Views | 13 Replies
New Topic Respond to this Topic

AS: Scrolling Object 2005-10-01 03:45:57


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

Response to AS: Scrolling Object 2005-10-01 04:28:32


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.


BBS Signature

Response to AS: Scrolling Object 2005-10-01 04:39:00


well ether way it still works

Response to AS: Scrolling Object 2005-10-01 04:42:23


cheers

Response to AS: Scrolling Object 2005-10-01 04:44:03


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...


BBS Signature

Response to AS: Scrolling Object 2005-10-01 04:46:26


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

Response to AS: Scrolling Object 2005-10-01 04:48:04


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


BBS Signature

Response to AS: Scrolling Object 2005-10-01 04:49:41


oh well who cares not me....

Response to AS: Scrolling Object 2005-10-01 04:51:58


I CARE >:(

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


BBS Signature

Response to AS: Scrolling Object 2005-10-01 04:59:59


Why do you keep making these n00by tutorials


- Matt, Rustyarcade.com

Response to AS: Scrolling Object 2005-10-01 05:32:30


its not a nOOby Tutorial

Response to AS: Scrolling Object 2005-10-01 05:35:04


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

Response to AS: Scrolling Object 2006-06-05 19:04:38


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

Response to AS: Scrolling Object 2007-12-13 12:21:06


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?