Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it L'avatar di Trinità76
    Registrato dal
    Jan 2002
    Messaggi
    1,439

    [MX] studiando come funziona il for...

    codice:
    function init(){
    w = 750;
    h = 400;
    spc = 40;
    Xamount = Math.round(w/spc);
    Yamount = Math.round(h/spc);
    n=0;
    r = random(3)*5;
    for (var x = 0; x < Xamount; x++) {
    for (var y = 0; y < Yamount; y++) {
    this.attachMovie("clip", "texture" + n, n);
    // il +6 e il +11 li ho messi io
    // per posizionare meglio le clip
    this["tex" + n]._x = ((spc) * x)+6;
    this["tex" + n]._y = ((spc) * y)+11;
    this["tex" + n]._alpha = 10+r;
    n++;
    }}}
    Si ha praticamente una clip copiata su una superficie con una distanza fissa. Fin qui ok.
    MA perchè se io metto
    codice:
    r = random(3)*5;
    e poi all'interno dei for
    codice:
    this["tex" + n]._alpha = 10+r;
    tutte le istanze duplicate prendono uno stesso valore random di _alpha, e non ogniuna con un valore random differente? Come si fa a renderlo così?
    わさび

  2. #2
    Utente di HTML.it L'avatar di negatyve
    Registrato dal
    Feb 2001
    Messaggi
    9,479
    Lo devi mettere dentro il for:

    codice:
    function init(){
    	w = 750;
    	h = 400;
    	spc = 40;
    	Xamount = Math.round(w / spc);
    	Yamount = Math.round(h / spc);
    	n = 0;
    	for (var x = 0; x < Xamount; x++) {
    		for (var y = 0; y < Yamount; y++) {
    			r = random(3) * 5;
    			this.attachMovie("clip", "texture" + n, n);
    			// il +6 e il +11 li ho messi io
    			// per posizionare meglio le clip
    			this["tex" + n]._x = ((spc) * x) + 6;
    			this["tex" + n]._y = ((spc) * y) + 11;
    			this["tex" + n]._alpha = 10 + r;
    			n++;
    		}
    	}
    }

  3. #3
    Utente di HTML.it L'avatar di Trinità76
    Registrato dal
    Jan 2002
    Messaggi
    1,439
    Originariamente inviato da negatyve
    Lo devi mettere dentro il for:

    codice:
    function init(){
    	w = 750;
    	h = 400;
    	spc = 40;
    	Xamount = Math.round(w / spc);
    	Yamount = Math.round(h / spc);
    	n = 0;
    	for (var x = 0; x < Xamount; x++) {
    		for (var y = 0; y < Yamount; y++) {
    			r = random(3) * 5;
    			this.attachMovie("clip", "texture" + n, n);
    			// il +6 e il +11 li ho messi io
    			// per posizionare meglio le clip
    			this["tex" + n]._x = ((spc) * x) + 6;
    			this["tex" + n]._y = ((spc) * y) + 11;
    			this["tex" + n]._alpha = 10 + r;
    			n++;
    		}
    	}
    }
    che carciofo che sono :quipy:
    わさび

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.