Help Me Keep My Circles Moving!

Ok I am trying to make a spaceship game and in order to make it look like my spaceship is moving I need to make my circles in the background move forever. I tried using the Continuous Movement tutorail but it makes my circles get bigger when I move my mouse and when I move my mouse all the way to the right it gets faster and left gets slower does anyone know how to change the actionscript for the circle movie clip to make it not do those things??? thanks btw the actionscript for the circle movieclip is

onClipEvent (enterFrame) {
//generating movement
location = this._x;
var i;
i = 1+_root._xmouse/5;
if (this, hitTest(_root.block)) {
this._x = -1000;
} else {
this._x = location+i++;
}
//clips are scaled according to y-mouse;
this._xscale = 40+_root._ymouse;
this._yscale = 40+_root._ymouse;
}

I would do it entirely differently.

using a “for…in” loop you could move all the circles at once.
altering the movie clip prototype you could set any circle to move from the back end back to the beginning of it’s movement again

Let me think about what code could do that. I’m sure that I can come up with something pretty simple.

Gonna go and read up on my for…in looping. brb

Here is the fix that you wanted from your code from before but I would take david’s suggestion and wait for him to cook you up some spiffy code!

**onClipEvent (enterFrame) {
    location = this._x;
    var i;
    i = 1;
    if (this, hitTest(_root.block)) {
        this._x = -1000;
    } else {
        this._x = location+i++;
    }
}**

Increase the ‘i’ variable if you want the rock to go faster!

alright… this is assuming that you know how to attach code to movie clips, and how to create functions (thought technicaly you don’t need to know how to do it, it will help you to understand what is going on.)

you may wish to create these circles dynamicaly, and randomly place their start location. This is the method I’m going to explain, but I’ll try to set up the script to do either that or a repeating pattern.

This also assumes that the circle clip is using it’s center as it’s registration poiint.

create a movie clip and inside of it place your circle movie clip.

give the circle an “Instance” name of “circle”

give the movie clip that contains the circle clip an Instance name of “circleClipContainer”.

attach this script to the outside of the “circleClipContainer”

onClipEvent(load){
//Set initial variables
//this assumes that you’re clips are moving right to left. set this
//number equal to the height of your stage.
circRad=this.circle._width/2;
//stage size
stageHeight=300;
stageWidth=500;
//this makes 30 circles
totalClips=30;
//loop to create more circles and place them.
for(i=0; i < totalClips; i++){
//take the circle clip and make many of them.
duplicateMovieClip(this.circle,“circle”+i,i);
this[“circle”+i]._y=(Math.random()*stageHeight+1)+circRad;
this[“circle”+i]._x=stageWidth+(Math.random()*stageWidth+1);
this[“circle”+i].startPos=this[“circle”+i]._x;
//the velocity is the speed the clip will travel at. if you would
//prefer that it not be random, simply change it to a number
this[“circle”+i].velocity=Math.random()*6+1;
}
}
onClipEvent(enterFrame){
for(i=0;i < totalClips;i++){
this[“circle”+i]._x-=this[“circle”+i].velocity;
if(this[“circle”+i]._x <= 0-circRad){
//uncomment this line if you want start pos to be random
//after each pass
//this[“circle”+i].startPos=stageWidth+(Math.random()*stageWidth+1);
this[“circle”+i]._x=this[“circle”+i].startPos;
//uncomment this line if you want velocity to change after
//each pass
//this[“circle”+i].velocity=Math.random()*6+1;
}
}
}


you might need to tweek this to get it to work correctly.

I’ve set it up so that 30 circles are spawned, each on apears for the first time randomly, off stage to the right. Each one has a random movement of 1 - 6 assigned to it.

The below example of the onClipEvent MAY work better. Try it out as well and see what kind of results you get on speed from each.

onClipEvent(load){
//Set initial variables
//this assumes that you’re clips are moving right to left. set this
//number equal to the height of your stage.
circRad=this.circle._width/2;
//stage size
stageHeight=300;
stageWidth=500;
//this makes 30 circles
totalClips=30;
//loop to create more circles and place them.
for(i=0;i < totalClips;i++){
//take the circle clip and make many of them.
duplicateMovieClip(this.circle,“circle”+i,i);
}
for(var property in this){
if(typeof this[property] ==“movieclip”){
this[property]._y=(Math.random()*stageHeight+1)+circRad;
this[property]._x=stageWidth+(Math.random()*stageWidth+1);
this[property].startPos=this[property]._x;
//the velocity is the speed the clip will travel at. if you would
//prefer that it not be random, simply change it to a number
this[property].velocity=Math.random()*6+1;
}
}
}
onClipEvent(enterFrame){
for(var property in this){
if(typeof this[property] ==“movieclip”){
this[property]._x-=this[property] .velocity;
if(this[property]._x <= 0-circRad){
//uncomment this line if you want start pos to be random
//after each pass
//this[property].startPos=stageWidth+(Math.random()*stageWidth+1);
this[property] ._x=this[property].startPos;
//uncomment this line if you want velocity to change after
//each pass
//this[property].velocity=Math.random()*6+1;
}
}
}
}

Mind you… I didn’t test either one of these. If they don’t work, write back and I’ll see what I might have done wrong.

enjoy

:o omg David :o :x

what??

Mmm… Nice, Upu!
A few things though: browsing through the objects of the current object isn’t really necessary since you know the names of the clips you’re looking for. On the contrary, there could be problems if for some reasons some other clips are there, don’t you think? I don’t know, we’d have to test the speed of each method.

And… can you use the code tag please :stuck_out_tongue: It’s much more readable that way…

pom :asian:

And you could do something cool too: duplicate the clips with random alpha to give a depth to your animation. I’m gonna try that, sounds fun :slight_smile:

pom :asian:

what??

omg = Oh My God! :slight_smile:
I was like… OMG what a post ya made! :slight_smile:

OK, I tested your code, Upu, it works like a charm. You have to put the container clip in the top left corner of the scene though, because the 0 of the circles are relative to it.

Last thing, I did that thing with the _alpha and the scale, and it looks pretty good. Here’s the code (indented :stuck_out_tongue: )

onClipEvent(load){
	//Set initial variables
	circRad=this.circle._width/2;
	stageHeight=300;
	stageWidth=500;
	//this makes 30 circles
	totalClips=30;
	//loop to create more circles and place them.
	for(i=0; i < totalClips; i++){
	//take the circle clip and make many of them.
		duplicateMovieClip(this.circle,"circle"+i,i);
		this["circle"+i]._y=(Math.random()*stageHeight+1)+circRad;
		this["circle"+i]._x=stageWidth+(Math.random()*stageWidth+1);
		this["circle"+i].startPos=this["circle"+i]._x;
	//the velocity is the speed the clip will travel at. if you would 
	//prefer that it not be random, simply change it to a number
		**var myNum=Math.random()*6+1;
		this["circle"+i].velocity=myNum;
		this["circle"+i]._alpha=10*myNum+20;
		this["circle"+i]._xscale=this["circle"+i]._yscale=10*myNum;**
	}
}
onClipEvent(enterFrame){
	for(i=0;i < totalClips;i++){
		this["circle"+i]._x-=this["circle"+i].velocity;
		if(this["circle"+i]._x <= -circRad){
		//uncomment this line if you want start pos to be random
		//after each pass
		//this["circle"+i].startPos=stageWidth+(Math.random()*stageWidth+1);
			this["circle"+i]._x=this["circle"+i].startPos;
		//uncomment this line if you want velocity to change after 
		//each pass
		//this["circle"+i].velocity=Math.random()*6+1;
		}
	}
}

In bold is what I added. I put the file for download. Nice work guys!

pom :asian:

I didn’t even know there was a code tag. I’ve been forced to “escape” my opening and closing carrots… Thank you Pom…knowing that is going to be very useful.