Starfield

Thanks a lot for the replies. Flex that is pretty much exactly what I had been looking for. Thanks :slight_smile: Same to you bezza. Pom, your tutorial is what got me back on the zooming star thing. After reading your tutorial, I decided to give that effect one last shot.

Cheers!
Kirupa :rambo:

Nice work guys!
Flex >> Very cool effect.
Bezzer >> What’s your method? Tweens or code? And strange thing: your stars appear quickly and then slow down, whereas it should be the opposite :slight_smile:

Here’s something based on the perspective tutorial (the engine is not mine, it’s Keith Peter’s. Make a large scene, a black background, and create a movie clip of a small dot with the linkage name “dot” and enter this cide (Flash MX):

/*********************
 Variables definition
   - fl: focal length
   - zspeed: dot speed
*********************/
fl = 200;
zspeed = 40;

/*********************
 _root enterFrame
   - creates a new dot
     every 150 ms
*********************/
onEnterFrame = function () {
	if (getTimer()-start>150) {
		start = getTimer();
		makeBox();
	}
};

/*********************
 Functions definition
   - makeBox: creates a new dot
      . (x,y): absolute coordinates (before scaling)
   - boxMove: moves the box :)
      . check the perspective tutorial
*********************/
function makeBox() {
	box = attachMovie("dot", "dot"+(++i), i);
	box.num=i;
	box._x=100000;
	box.x = random(4000)-2000;
	box.y = random(3000)-1500;
	box.z = 2500;
	box.xspeed = Math.sin(xangle+=.2)*1;
	box.yspeed = Math.sin(yangle+=.5)*1;
	box.onEnterFrame = boxMove;
};
function boxMove() {
	this.z -= zspeed;
	this.x += (270-_xmouse)*.05;
	this.y += (200-_ymouse)*.05;
	this.x += this.xspeed;
	this.y += this.yspeed;
	this.scale = fl/(fl+this.z);
	this._x = this.x*this.scale+270;
	this._y = this.y*this.scale+200;
	this._xscale = this._yscale=this.scale*100;
	this._alpha = (2500-this.z)*.1;
	if (this.z<-fl/2) {
		removeMovieClip(this);
	}
};

Enjoy. :slight_smile:

pom :asian:

Wow, that is pretty amazing. So simple, yet so complex.

… and so CPU consuming, unfortunately. But hey, you can’t have an omelette without breaking eggs (French saying, nevermind).

Makes sense, it didn’t seem to consume too much of my resources, unless I just wasn’t paying enough attention.

Decrease 150 and you should see… and if you don’t, congratulations, you assembled a great computer :slight_smile:

pom :asian:

I kept decreasing 150 by 50 until I got to 1, still no lagging. I even opened up and use other programs and it all ran smoothly.

I guess my comp is having a good day. It is a 700Mhz with 128Mb Ram, so its not incredible. I built it about a year ago:)

:x :x :x Must be my comp then… Darn laptops really suck. Does it look better with more stars?

pom :asian:

It looks much better with more stars:)

Sorry to stray Ilyas, but do you know how to reset the getTimer() function? I could easily look for it on the web, but hey, figured I would ask you.

I want something to pause for about 3 seconds and have it start again, but it has to loop around so when it starts over again, I want the timer to be reset. Do you know how to do that?

getTimer can’t be reset, it is the time elapsed since the beginning of the clip. All you’ve got to do is work with time spans (I hope all those words exist in English…).

timeStart=getTimer();
if (getTimer()-start<3000){
   // do what you want
} else {
  // timeStart=getTimer();
}

What are you trying to do? If I may ask :slight_smile:

pom :asian:

All those words exist in english:) I don’t really understand what to do with that code. Maybe because it is almost 3am here.

This is what I am trying to do…
[swf=“http://www.8ballcreations.com/lostinbeta/colorFadeFooter.swf height=60 width=300”][/swf]

See how the first time it delays? Well I want it to do that each time instead of just the first.

I don’t see a delay… but I do understand what Pom is talking about. Perhaps if I show my methods it will make more sense to you… don’t know yet. :slight_smile:

I use oldtimer newtimer

somewhere in the beginning of my movie I place

oldtimer=getTimer();

Then I just keep reseting oldtimer when I need to. The timer itself is arbitrary once you’ve asigned it to a variable. from then on your just subtracting times. so…

lets say you delay the root timeline.

newTimer=getTimer();
if(newTimer-oldTimer<4000){
gotoAndPlay(6);
}else{
oldTimer=newTimer;
gotoAndPlay(10);
}

you’re just setting up a loop where it waits to go forward until the difference between oldTimer and newTimer is a certain amount. When that does happen, the playhead moves to the next frame after the oldTimer is set to the newTimer amount.

The next time this is checked… the oldTimer is bigger than it was in the beginning… and consiquently set to be used for the same difference equation.


to be tricky, if I were going to do this many times and possibly to many different objects… I’d set it up as a function rather than frame script.

Hey david,

Thanks, that worked perfectly! I know have a 1 framed, no movie clip random gradient generator!

cool…

Now to make it bigger than the example above (few posts back) and add it to my experimental section on my site=)

Nice! Are you using beginGradientFill or just doing it by hand?

pom :asian:

It is just beginFill and it draws and then duplicates the same clip sideways, while slightly changing the color.

Well you should try with the gradient. A bit hard to use at first, but it totally kicks as$. It’s fairly well explained in the AS Dictionary.

pom :asian:

Hmmm, I think I will do that sooner or later. I was looking at the beginGradientFill before and it looked too complicated, so I created a gradient myself out of rectangles…haha:P

I still have to get back to work on my 3D engine. I kind of left that for a while there.

Gradients ARE complicated. I didn’t get until someone explained them to me. Well, maybe a future AS trick or a tutorial…

And good luck with that 3D engine. :slight_smile: (that could be a nice tutorial to make too…)

pom :asian: