A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Looping 1-framed Animated Actionscripted Background (starry)

  1. #1
    A Flurry of Activity
    Join Date
    Aug 2005
    Posts
    103

    Looping 1-framed Animated Actionscripted Background (starry)

    I was very surprised this wasnt asked before O.O i did my search

    Anyway heres my question - what would be the most efficient way (trying not to compromise on all the other things going on at the same time (this is just an animated background, a game plays on the higher lvl, i just want this under it)
    To have a star-field background, where stars float up randomly from top to bottom and with random sizes and positions.

    I know this much: make a single star. check.
    Make the background layer. check.

    Code:
    for (N=0; N<=22; N++) {
    _root.attachMovie("Star", "cell"+N, 0);
    _root["cell"+N]._x = Random(550);
    _root["cell"+N]._y = 0;
    _root["cell"+N]._xscale = Random(5);
    _root["cell"+N]._yscale = Random(5);
    _root["cell"+N+speed] = Random(5);
    Next N
    ^Places 22 stars. (i think). Check.
    I then need a script that runs in between "placements" of the stars, and makes them float down. (with the randomized speed).

    I'm just having logical problems with "where to place the codes" Because there arent actual "subroutines" i can access on... Time values, maybe? like every 2 seconds it makes new / deletes old / and moves the stars that are currently out? or is there a better way.

    In other words, i tried to phrase my question to get the most "alternative methods" to achieve what i want. (In case you havent guessed, i am demonically contributing to the already hellish amounts of SHMUP's online... (its a good exercise - no flame plox))

    IN OTHER WORDS - its just a randomized starfield running on 1 frame completely actionscript made (excepting the background solid color + the star movieclip. should be very small in size.)


    ACTUALLY: EVEN BETTER WAY: a script that constantly checks up on values / movieclips and then executes stuff on them - but while still leaving enough space in between "check ups" so that the other layers can keep "doing their thing"
    Last edited by taifunbrowser; 06-17-2006 at 05:05 PM.
    maximum width 300 no more maximum hieght 40 no more not interchangable

  2. #2
    Senior Member
    Join Date
    May 2002
    Posts
    1,017
    Code:
    for (N=0; N<=22; N++) {
    	_root.attachMovie("star", "cell"+N, _root.getNextHighestDepth()); // in your code you would overwrite the movieclips if you attach all in the same level 0
    	_root["cell"+N]._x = random(550);
    	_root["cell"+N]._y = random(400); //so you get the starfield look from the beginning
    	_root["cell"+N]._xscale = 50+random(50);// this I changed cause I drew the stars really small so a scale of 0 to 4 would render them practically invisible
    	_root["cell"+N]._yscale = 50+random(50);
    	_root["cell"+N].speed = random(5)+1; // + 1 because the random function returns value from 0 to 4 so you would eventaully end with not moving stars
    	_root["cell"+N].onEnterFrame = function() { //on each frame
    		this._y += this.speed; // move down by the value of the variable speed for that star
    		if (this._y>400) { //if _y is bigger then the hight
    			this.speed = random(5)+1; //set new random speed
    			this._y = 0; //move it on top to go again
    		}
    	};
    }
    Last edited by Smilev; 06-17-2006 at 05:48 PM.
    while (2+2 == 4) {
    drink ("bourbon");
    }
    gotoAndStop("bed");

  3. #3
    A Flurry of Activity
    Join Date
    Aug 2005
    Posts
    103

    asdf

    i coulda done that myself >_> thats the simple stuff

    the problem i'm having is that its all on one frame! (games tend to be that way)

    so? how do i get the function to run rapidly, but not constantly (that = crash), and i dont think i can use onenterframe... cuz its on one frame.

    damit. Or, does anyone have a miracle solution to perhaps, laying out the game so that it runs on multiple frames? single frame seems the only way to me >_>

    OH: if i came across b1tchy, its cuz i am having a bad day, but on edit: thx for the advice smily, i prob would have forgotten to do some of that
    Last edited by taifunbrowser; 06-17-2006 at 09:24 PM.
    maximum width 300 no more maximum hieght 40 no more not interchangable

  4. #4
    Senior Member
    Join Date
    May 2002
    Posts
    1,017
    So what's the problem of using onEnterFrame and being on one frame? I sort of can't understand what you are trying to say ... can you?

    P.S. Have you even try the code?
    while (2+2 == 4) {
    drink ("bourbon");
    }
    gotoAndStop("bed");

  5. #5
    Knows where you live
    Join Date
    Oct 2004
    Posts
    944
    onEnterFrame will work.
    The greatest pleasure in life is doing what people say you cannot do.
    - Walter Bagehot
    The height of cleverness is to be able to conceal it.
    - Francois de La Rochefoucauld

  6. #6
    A Flurry of Activity
    Join Date
    Aug 2005
    Posts
    103

    sdfg

    OH!

    it does >_> dam i feel stupid.

    its illogical, but it works . so "stop()" is actually more of "keep looping this frame"?! cool!

    EDIT: wait, no it doesnt >_> i did test it... i see nothing

    hmm i tried it on a movieclip and on the frame itself, its on the top layer... sigh its not syntaxed wrong but just not seeing anything.

    EDIT: alright, the debugging shows that it doesnt have a problem with the onenterframe part ()

    its the part before that, the debug goes by the steps that say "attach movieclip" and such, but they dont appear on screen >_>...

    OH GOD how could i be so stupid >_> i didnt have the item in the library "ready for actionscript exporting"... oh well stupid mistake number one
    Last edited by taifunbrowser; 06-18-2006 at 08:22 AM.
    maximum width 300 no more maximum hieght 40 no more not interchangable

  7. #7
    Senior Member
    Join Date
    May 2002
    Posts
    1,017
    It's not illogical at all Every movieclip in a flash movie has it's own timeline. Basically the onEnterFrame happens so many time per seconds as your fps is set to. The _root is a movie clip too, so if you assign onEnterFrame event, it executes the code 30 times if your fps is set to 30.
    while (2+2 == 4) {
    drink ("bourbon");
    }
    gotoAndStop("bed");

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center