View Full Version : need help making random twinkling stars
tali96
02-15-2005, 08:22 PM
I want to make twinkling stars in the night sky...can someone help give me some examples for this...i tried making a movieclip that had the alpha go form 0 to 100 and back...and other suggestions?
emergency_pants
02-16-2005, 02:17 PM
how about setting _alpha randomly on enterFrame ? eg starcity attached
var numStars:Number = 50;
for (i=1; i<=numStars; i++) {
_root["star"+i].onEnterFrame = function() {
this._alpha = Math.random()*40+60;
this._rotation+=10;
};
}
or how about doing as you say and having the alpha run from say 40 to 100, but vary the speed? This looks much nicer. eg starcity2 attached
var numStars:Number = 50;
for (i=1; i<=numStars; i++) {
_root["star"+i].rotSpeed = Math.round(Math.random()*8+2);
_root["star"+i].tranSpeed = Math.round(Math.random()*10+5);
_root["star"+i].tranDir = Math.floor(Math.random()*2);
_root["star"+i].onEnterFrame = function() {
if (this.tranDir == 0) {
this._alpha += this.tranSpeed;
if (this._alpha>100) {
this.tranDir = 1;
}
} else {
this._alpha -= this.tranSpeed;
if (this._alpha<40) {
this.tranDir = 0;
}
}
this._rotation += this.rotSpeed;
};
}
tali96
02-16-2005, 06:35 PM
whats the best way to make random stars that twinkle off and on at random speeds and brightness? I want this to happen continously in the background of my movie clip.
emergency_pants
02-16-2005, 06:42 PM
?
http://www.actionscript.org/forums/showthread.php3?t=65226
Is this not what you are after?
tali96
02-16-2005, 06:48 PM
this is pretty cool...but i was after a shine effect that looks like the actual stars in the sky..but thanks i think i might be able to modify this script
carlos_queiroz
02-16-2005, 06:56 PM
hi tali
see if you like this stars
tali96
02-16-2005, 06:58 PM
why does and out put with numbers show up when i run this movie??
carlos_queiroz
02-16-2005, 07:06 PM
hi tuli
see this starts
http://pwp.netcabo.pt/carlos_queiroz/stars.swf
if you like it
http://pwp.netcabo.pt/carlos_queiroz/stars.fla
tali96
02-16-2005, 07:12 PM
this is pretty cool....yeah thats what i was trying to do a combination of yours and emergency pants..pretty cool...
tali96
02-16-2005, 07:15 PM
what are some more events besides onrollover...to make the stars shine witout mouse action?
carlos_queiroz
02-16-2005, 07:25 PM
the rollover is a mouse action
when you rollover them, they play
when you rollout the gotostop(1);
its to control the shinning efect
maybe I used to many stars
tali96
02-16-2005, 07:39 PM
i got the stars to shine without the rollover...now i am trying to get them to work inside of a movie clip that is on the stage..not just all over the stage..
carlos_queiroz
02-16-2005, 07:41 PM
guess thats easy
glad i could help
bye
emergency_pants
02-17-2005, 09:35 AM
You probably have this all sorted by now, but I improved it a bit for my own interest. So I thought I'd share it.
Creates a new movieClip, places the stars inside. Star has a twinkle animation which has a 1/500 chance of playing.
var numStars:Number = 500;
this.createEmptyMovieClip("starField_mc", 1);
var dice:Number;
for (i=1; i<=numStars; i++) {
_root.starField_mc.attachMovie("star", "star"+i, i, {_x:Math.random()*Stage.width, _y:Math.random()*Stage.height, _alpha:Math.random()*100});
_root.starField_mc["star"+i].tranSpeed = Math.round(Math.random()*10+5);
_root.starField_mc["star"+i].onEnterFrame = function() {
twinkle(this);
if (this.tranDir == 0) {
this._alpha += this.tranSpeed;
if (this._alpha>100) {
this.tranDir = 1;
}
} else {
this._alpha -= this.tranSpeed;
if (this._alpha<60) {
this.tranDir = 0;
}
}
};
}
function twinkle(clip) {
//roll a dice 1-500
//1 in 500 chance of twinkling
dice = Math.round(Math.random()*500);
if (dice == 1) {
clip.play();
}
}
tali96
02-17-2005, 10:10 PM
thanks that looks really good. I was having trouble making it work for me....cool
one last question? my stage is 700px I only want the stars to play about 410px on the left side of the stage.
any sugestions? i tried to change the stage width but it did not work for me
ascreed
07-12-2005, 03:15 AM
I'm sure this is a completely moronic question, but I'm a newbie to ActionScript.
How do you mask this? I tried creating starcity3 as a swf file and importing and masking - no go.
Basically I have a design where I'd like to have random stars twinkling above the roofline.
Thanks for any help.
SuperApe
07-12-2005, 04:43 PM
one last question? my stage is 700px I only want the stars to play about 410px on the left side of the stage.
The left side? It looks like you could just change the line:
_root.starField_mc.attachMovie("star", "star"+i, i, {_x:Math.random()*Stage.width, _y:Math.random()*Stage.height, _alpha:Math.random()*100});
...to this:
_root.starField_mc.attachMovie("star", "star"+i, i, {_x:Math.random()*410, _y:Math.random()*Stage.height, _alpha:Math.random()*100});
...(notice the _x: change)
I'm sure this is a completely moronic question, but I'm a newbie to ActionScript.
How do you mask this? I tried creating starcity3 as a swf file and importing and masking - no go.
Basically I have a design where I'd like to have random stars twinkling above the roofline.
Thanks for any help.
This is similar to a question I have struggled with recently. I hope I can help.
(and if not, we'll both learn)
The first obvious thing to try was to add a mask object above the layer with the code in it and mask the layer below. This won't work because dynamically created mc's appear in their own timeline above all the _root layers by default. So, some reorganizing must be done to get those to mask.
Let's say, right now the code is on the timeline (frame 1). And there's a star mc with twinkle animation on it. So when the twinkle function runs, it simply plays the clip. (if I'm reading the code right, that's what's happening)
If this code were placed within an mc that contained the star mc, you could mask the container. The code could be changed to duplicate the stars from within the container and the duplicate should appear on the masked layer.
Another option is to create a mask mc and set that to a layer well above the 500 stars that are being attached now.
Someone knowledgable want to go over this idea and correct me where I'm wrong? Thanks.
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.