Zurück   Flashforum > Flash > ActionScript > ActionScript 1

Antwort
 
LinkBack Themen-Optionen Ansicht
Alt 13-09-2005, 20:21   #1 (permalink)
twisted mind
 
Benutzerbild von buttermilk
 
Registriert seit: Aug 2004
Beiträge: 23
boxfield effekt

Huhu,

gestern hat mich mal wieder die flash lust gepackt und ich habe einen kleinen "starfield effekt" mit boxen geschrieben. Im Endeffekt läuft er so wie geplant, allerdings finde ich zwei sachen irgendwie unsauber.
Vielleicht habt ihr ne Idee wie man das besser machen kann .

Hier ist der Clip

hier ein bisschen code
ActionScript:
  1. /********************************************
  2. * blockfield effekt
  3. * generats a starfield of blocks
  4. ********************************************/
  5.  
  6. onClipEvent(load){
  7.    
  8.     // initvars
  9.    
  10.     n = 80; //blocks
  11.     maxdist = 800; //startdistance
  12.     speed = 5; //blockspeed
  13.     height=300; //viewport height
  14.     width=600; //viewport width
  15.     startfieldwidth=width*maxdist/2; //box starting retangle height
  16.     startfieldheight=height*maxdist/2; //box starting retangle width
  17.     scalefac = 0.2; //max box scaling
  18.     delay = 100; //starting delay in frames
  19.     xstart = width/2;
  20.     ystart = height/2;
  21.  
  22.  
  23.     /////////////////////////////////////
  24.     // initalize box clip after ataching
  25.     /////////////////////////////////////
  26.    
  27.     function initbox(clip){
  28.    
  29.         x=Math.random()*startfieldwidth - startfieldwidth/2;
  30.         y=Math.random()*startfieldheight - startfieldheight/2;
  31.         z=Math.random()*maxdist;
  32.        
  33.         _root[clip].delay = Math.random()*delay;
  34.         _root[clip].x=x;
  35.         _root[clip].y=y;
  36.         _root[clip].z=200;
  37.        
  38. _root[clip].swapDepths((maxdist-_root[clip].z)*10+1000+math.random()*10);
  39.  
  40.         rotate(clip,10);
  41.         updatebox(clip);
  42.     }
  43.    
  44.     /////////////////////////////////////
  45.     // rotate box clip 
  46.     /////////////////////////////////////
  47.    
  48.     function rotate(clip,deg){
  49.         _root[clip].box.gotoAndStop(math.floor(deg/10));
  50.     }
  51.  
  52.     /////////////////////////////////////////////////////
  53.     // initalize boxfield: create box clip and init it
  54.     ////////////////////////////////////////////////////
  55.    
  56.     function initstarfield(){
  57.         for(i=1;i<n;i++){
  58.         _root.attachMovie("bb", "box"+i, i);
  59.         initbox("box"+i);
  60.         }
  61.     }
  62.    
  63.     ///////////////////////////////////////////////////
  64.     // update boxfield (will be called every frame
  65.     ///////////////////////////////////////////////////
  66.    
  67.    
  68.     function updatestarfield(){
  69.         for(i=1;i<n;i++){
  70.             _root["box"+i].z-=speed;
  71.             updatebox("box"+i);
  72.         }
  73.     }
  74.    
  75.     ///////////////////////////////////////////////////
  76.     // reset box if its out of bounds
  77.     ///////////////////////////////////////////////////
  78.  
  79.     function resetbox(clip){
  80.         x=Math.random()*startfieldwidth - startfieldwidth/2;
  81.         y=Math.random()*startfieldheight - startfieldheight/2;
  82.         z=maxdist
  83.    
  84.         x0 = x/z +xstart;
  85.         y0 = y/z +ystart;
  86.        
  87.         _root[clip].x=x;
  88.         _root[clip].y=y;
  89.         _root[clip].z=z;
  90.  
  91.         _root[clip]._x=x0;
  92.         _root[clip]._y=y0;
  93.        
  94.         rotate(clip,0);
  95.        
  96.         _root[clip].swapDepths((maxdist-_root[clip].z)*10+1000+math.random()*10);
  97.        
  98.     }
  99.    
  100.     ///////////////////////////////////////////////////
  101.     // update visual appearance
  102.     ///////////////////////////////////////////////////
  103.    
  104.    
  105.     function updatebox(clip){
  106.         if(_root[clip].delay<=0) {
  107.            
  108.             _root[clip]._visible = true;
  109.            
  110.             if(_root[clip].z<0) resetbox(clip) ;
  111.             if(_root[clip]._y<=0||_root[clip]._y>=height) resetbox(clip);
  112.             if(_root[clip]._x<=0||_root[clip]._x>=width) resetbox(clip);
  113.            
  114.            
  115.             x0 = _root[clip].x/_root[clip].z +xstart;
  116.             y0 = _root[clip].y/_root[clip].z +ystart;
  117.            
  118.             _root[clip]._x=x0;
  119.             _root[clip]._y=y0;
  120.            
  121.             _root[clip]._xscale = (1 - ( _root[clip].z  / maxdist ))*100*scalefac ;
  122.             _root[clip]._yscale = (1 - ( _root[clip].z  / maxdist ))*100*scalefac ;
  123.            
  124.             //deg = math.asin(math.abs(width/2-_root[clip].x)/math.sqrt(_root[clip].z*_root[clip].z+(_root[clip].x-width/2)*(_root[clip].x-width/2)))
  125.             //deg = deg/math.PI * 180;
  126.            
  127.            
  128.             deg = math.abs(_root[clip]._x-width/2)/(width/2)*60;
  129.             if(_root[clip].x-width/2>0) deg = 360-deg;
  130.             deg += 10;
  131.             rotate(clip, deg);
  132.            
  133.    
  134.             _root[clip].swapDepths((maxdist-_root[clip].z)*10+1000+math.random()*10);
  135.        
  136.            
  137.         }
  138.        
  139.         else {_root[clip].delay--;
  140.         _root[clip]._visible = false;}
  141.        
  142.     }
  143.    
  144.    
  145.     initstarfield(); //initstarfield once
  146. }
  147.  
  148. onClipEvent(enterFrame){
  149.     updatestarfield(); //update starfield
  150. }

Hier ist der Clip

Zum einen gefällt mir irgendwie meine Lösung zum errechnen des nötigen Blickwinkels zu Drehung des Blockes nicht und zum anderen frage ich mich warum ich zu der depth einen random wert addieren muss, damit die dinger aufhören zu flackern.

Vielleicht habt ihr ne Idee. Auch ist allgemeine Kritik gewünscht wenn euch sonst irgendwas nicht gefällt oder gut gefällt.

gruss
butter
__________________
a drunk man will find his way home, but a drunk bird may get lost forever
buttermilk ist offline   Mit Zitat antworten
Antwort

Lesezeichen

Themen-Optionen
Ansicht

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks sind an
Pingbacks sind an
Refbacks sind an



Alle Zeitangaben in WEZ +1. Es ist jetzt 21:37 Uhr.

Domains, Webhosting & Vserver von Host Europe
Unterstützt das Flashforum!
Adobe User Group


Copyright ©1999 – 2012 Marc Thiele