Visualizzazione dei risultati da 1 a 4 su 4
  1. #1

    duplicare un mc e caricarlo random

    vorrei duplicare un clip e caricarlo random (più volte lo stesso ad intervalli casuali) sull'asse delle x di un mc target.
    si può fare?
    Qualcuno mi suggerisce lo script per favore?
    Grazie a tutti!
    Silvia
    ...e quindi uscimmo a riveder le stelle..
    http://www.silviamato.it
    http://alano.silviamato.it

  2. #2
    Utente di HTML.it L'avatar di CJ 87
    Registrato dal
    Dec 2006
    Messaggi
    43
    Ciao, farlo sicuramente si può...
    Ma devo capire bene cosa vuoi fare se vuoi una cosa che continua a muoversi? Se è così allora:

    Crea un piccolo MC (io ho fatto un piccolo cerchietto vuoto, solo la linea) e lo metti nella libreria chiamalo "ball" (tasto destro su l'MC - linkage - export for action script)
    Sul primo frame metti questo:
    codice:
    var totMC:Number = 20;
    for (var i = 0; i<totMC; i++) {
    var t = this.attachMovie("ball", "ball"+i, i+1);
    t._x = Math.random()*Stage.width
    t._y = Math.random()*Stage.height
    t.dx = Math.round(Math.random()*Stage.width);
    t.dy = Math.round(Math.random()*Stage.height);
    t.onEnterFrame = mover;
    }
    function mover() {
    this._x += (this.dx-this._x)/3;
    this._y += (this.dy-this._y)/3;
    if (Math.round(this._x) == this.dx) {
    this.dx = Math.round(Math.random()*Stage.width);
    this.dy = Math.round(Math.random()*Stage.height);
    }
    }
    Se lo vuoi fermo, che solo una volta vadano random:

    codice:
    var totMC:Number = 20;
    for (var i = 0; i<totMC; i++) {
    var t = this.attachMovie("ball", "ball"+i, i+1);
    t._x = Math.random()*Stage.width
    t._y = Math.random()*Stage.height
    t.dx = Math.round(Math.random()*Stage.width);
    t.dy = Math.round(Math.random()*Stage.height);
    t.onEnterFrame = mover;
    }
    function mover() {
    this._x += (this.dx-this._x)/3;
    this._y += (this.dy-this._y)/3;
    }
    Altrimenti spiega meglio così capisco... Ciao!
    Ciao, Salvo.

  3. #3
    Credo che questo sia il codice che mi interessa
    ma posso chiederti ancora se è quello che hop colorato il nome del mc da duplicare e caricare random?
    *Stage.width e qui inserisco cosa la larghezza totale dell'asse delle x?
    Mi serve che si carichi solo su quest'asse e non anche sull'altezza...


    var totMC:Number = 20;
    for (var i = 0; i<totMC; i++) {
    var t = this.attachMovie("ball", "ball"+i , i+1);
    t._x = Math.random()*Stage.width
    t._y = Math.random()*Stage.height
    t.dx = Math.round(Math.random()*Stage.width);
    t.dy = Math.round(Math.random()*Stage.height);
    t.onEnterFrame = mover;
    }
    function mover() {
    this._x += (this.dx-this._x)/3;
    this._y += (this.dy-this._y)/3;
    if (Math.round(this._x) == this.dx) {
    this.dx = Math.round(Math.random()*Stage.width);
    this.dy = Math.round(Math.random()*Stage.height);
    }
    }
    Silvia
    ...e quindi uscimmo a riveder le stelle..
    http://www.silviamato.it
    http://alano.silviamato.it

  4. #4
    Utente di HTML.it L'avatar di CJ 87
    Registrato dal
    Dec 2006
    Messaggi
    43
    Ciao,
    si
    codice:
    var t = this.attachMovie("ball", "ball"+i , i+1);
    Il primo "ball" è quello che va a prendere dalla libreria, e il secondo è il nuovo nome che gli assegna, in questo caso "ball"+i, cioè "ball1", "ball2", "ball3", etc..

    Per usarlo solo sull'asse _x metti:

    codice:
    var totMC:Number = 20;
    for (var i = 0; i<totMC; i++) {
    var t = this.attachMovie("ball", "ball"+i , i+1);
    t._x = Math.random()*Stage.width
    t.dx = Math.round(Math.random()*Stage.width);
    t.onEnterFrame = mover;
    }
    function mover() {
    this._x += (this.dx-this._x)/3;
    if (Math.round(this._x) == this.dx) {
    this.dx = Math.round(Math.random()*Stage.width);
    }
    }
    Però così ti si creeranno tutti sull'asse _y=0 quindi devi dargli almeno un indicazione e puoi mettere:

    codice:
    var totMC:Number = 20;
    for (var i = 0; i<totMC; i++) {
    var t = this.attachMovie("ball", "ball"+i , i+1);
    t._x = Math.random()*Stage.width
    t._y = 200
    t.dx = Math.round(Math.random()*Stage.width);
    t.onEnterFrame = mover;
    }
    function mover() {
    this._x += (this.dx-this._x)/3;
    if (Math.round(this._x) == this.dx) {
    this.dx = Math.round(Math.random()*Stage.width);
    }
    }
    Per "t._x = Math.random()*Stage.width"
    Puoi mettere la distanza in numeri che ti serve, ho messo per tutta la lunghezza dell stage in questo caso.
    Ma puoi benissimo mettere: t._x = Math.random()*mySize
    dove "mySize" è una variabile a cui assegni il numero che vuoi e poi cambi tutti gli altri:

    codice:
    var totMC:Number = 20;
    var mySize:Number = 200
    for (var i = 0; i<totMC; i++) {
    var t = this.attachMovie("ball", "ball"+i , i+1);
    t._x = Math.random()*mySize
    t._y = 200
    t.dx = Math.round(Math.random()*mySize );
    t.onEnterFrame = mover;
    }
    
    function mover() {
    this._x += (this.dx-this._x)/3;
    if (Math.round(this._x) == this.dx) {
    this.dx = Math.round(Math.random()*mySize );
    }
    }
    Ciao, Salvo.

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.