Strona 1 z 1
Kod, a wersja flasha
: sob cze 30, 2007 12:54 pm
autor: Thorus
Dlaczego ten kod nie dziala dla wersji flasha 8.0? Chodzi poprawnie jedynie gdy publish settings ustawie na flash 5.0. Czy ktos moglby mi powiedziec gdzie tkwia bledy tego kodu i jak je dostosowac do 8.0?
Ponadto jak widac kod jest wewnatrz MC, czy mozna go zostawic w takiej postaci wogole? Czy trzeba go dostosowac do TimeLine?
Kod: Zaznacz cały
onClipEvent(load){
homeX = this._x
homeY = this._y
magnet = 2000
}
onClipEvent(enterFrame){
x0 = this._x
y0 = this._y
x1 = _root._xmouse
y1 = _root._ymouse
distancex = x1-x0
distancey = y1-y0
distance = Math.sqrt((distancex * distancex) + (distancey * distancey))
powerx = this._x - (distancex / distance) * magnet / distance
powery = this._y - (distancey / distance) * magnet / distance
forcex = (forcex + (homex - x0) / 2) / 1.66
forcey = (forcey + (homey - y0) / 2) / 1.66
this._x = powerx + forcex
this._y = powery + forcey
}
Re: Kod, a wersja flasha
: sob cze 30, 2007 1:33 pm
autor: Marek_bf
Od AS2 ważna jest wielkość liter w zmiennych zmiennaJeden i zmiennajeden to są dwie różne zmienne.
Od wersji 6 Flasha nie jest zalecane przypisywanie kodu wewnatrz okna skryprowego obiektu tylko na timeline.
Re: Kod, a wersja flasha
: sob cze 30, 2007 1:48 pm
autor: Thorus
Poprawilem wiec: homex i homey na homeX i homeY, ale to nic nie dalo. Czy oprocz roznicy wielkosci liter jest tam jeszcze cos zle? Kod ten jest umieszczony w kilku mc. Po najechaniu kursorem na nie, obiekty maja odpychac sie od siebie (taki efekt magnesu).
Re: Kod, a wersja flasha
: sob cze 30, 2007 3:47 pm
autor: Marek_bf
Zmienne prowadzące obliczenia na własnych wartościach muszą mieć przypisane wartości początkowe.
Kod: Zaznacz cały
var i:Number;
i++;
trace("i = " + i);
//
var j:Number = 0;
j++;
trace("j = " + j);
W przypadku Twojego kodu są to: forcex i forcey.
Jednak, dobrym nawykiem jest deklaracja zmiennych na początku skryptu:
Kod: Zaznacz cały
var x0:Number, y0:Number, x1:Number, y1:Number, distancex:Number, distancey:Number, distance:Number, powerx:Number, powery:Number;
var homex:Number = my_mc._x;
var homey:Number = my_mc._y;
var magnet:Number = 2000;
var forcex:Number = 0;
var forcey:Number = 0;
my_mc.onEnterFrame = function() {
x0 = this._x;
y0 = this._y;
x1 = _xmouse;
y1 = _ymouse;
distancex = x1 - x0;
distancey = y1 - y0;
distance = Math.sqrt((distancex * distancex) + (distancey * distancey));
powerx = this._x - (distancex / distance) * magnet / distance;
powery = this._y - (distancey / distance) * magnet / distance;
forcex = (forcex + (homex - x0) / 2) / 1.66;
forcey = (forcey + (homey - y0) / 2) / 1.66;
this._x = powerx + forcex;
this._y = powery + forcey;
};
Bardziej elastycznie, w funkcji:
Kod: Zaznacz cały
foo(my_mc);
//
function foo(my_mc:MovieClip):Void {
var x0:Number, y0:Number, x1:Number, y1:Number, distancex:Number, distancey:Number, distance:Number, powerx:Number, powery:Number;
var homex:Number = my_mc._x;
var homey:Number = my_mc._y;
var magnet:Number = 2000;
var forcex:Number = 0;
var forcey:Number = 0;
my_mc.onEnterFrame = function() {
x0 = this._x;
y0 = this._y;
x1 = _xmouse;
y1 = _ymouse;
distancex = x1 - x0;
distancey = y1 - y0;
distance = Math.sqrt((distancex * distancex) + (distancey * distancey));
powerx = this._x - (distancex / distance) * magnet / distance;
powery = this._y - (distancey / distance) * magnet / distance;
forcex = (forcex + (homex - x0) / 2) / 1.66;
forcey = (forcey + (homey - y0) / 2) / 1.66;
this._x = powerx + forcex;
this._y = powery + forcey;
};
}
Re: Kod, a wersja flasha
: pn lip 02, 2007 10:45 am
autor: Thorus
http://w3.tyszkiewicz.edu.pl/~mamedrzak/muchy.fla
http://w3.tyszkiewicz.edu.pl/~mamedrzak/muchy2.fla
Pogubilem sie juz w tym wszystkim. Nie dziala mi to :/
Tu jest wersja dla flasha 5 i ta Twoja dla 8. Kod w klatce, instance name jest, czego tu jeszcze brakuje? Gdybys mial chwile zerknac...

:)
Re: Kod, a wersja flasha
: pn lip 02, 2007 12:05 pm
autor: Marek_bf
1. Nie możesz nadawać wielu obiektom umieszczonym na jednej scenie tej samej instancji.
2. Funkcję musisz przypisać do każdego obiektu oddzielnie.
http://download.yousendit.com/E0F6CE8D42F34CF9
Re: Kod, a wersja flasha
: pn lip 02, 2007 12:17 pm
autor: Thorus
Heh, caly czas sie ucze... Wielkie wielkie dzieki

P.S. Moglbys tylko jeszcze mi powiedziec w jaki sposob one sa teraz rozmieszczane na ekranie. Wydaje mi sie ze losowo, a wiec pojawil sie problem, poniewaz zalezalo mi na ich recznym ustawieniu. Chcialem je ukladac w odpowiednie ksztalty, w danych miejscach a teraz nie moge...
Re: Kod, a wersja flasha
: pn lip 02, 2007 12:32 pm
autor: Marek_bf
Nadajesz każdemu obiektowy nazwę mucha1, mucha2, mucha3 itp
Wywołujesz tyle razy funkcję ile ma byc much:
Dodaj do fukcji kod startujący każdą muchę w losowej klatce, tak żeby było złudzenie, iż każda mucha wykonuje inne ruchy:
Kod: Zaznacz cały
mucha.gotoAndPlay(1 + Math.round(Math.random() * mucha._totalframes));
////////
Kod: Zaznacz cały
function foo(mucha:MovieClip):Void {
var x0:Number, y0:Number, x1:Number, y1:Number, distancex:Number, distancey:Number, distance:Number, powerx:Number, powery:Number;
var homex:Number = mucha._x;
var homey:Number = mucha._y;
var magnet:Number = 2000;
var forcex:Number = 0;
var forcey:Number = 0;
mucha.gotoAndPlay(1 + Math.round(Math.random() * mucha._totalframes));
mucha.onEnterFrame = function() {
x0 = this._x;
y0 = this._y;
x1 = _xmouse;
y1 = _ymouse;
distancex = x1 - x0;
distancey = y1 - y0;
distance = Math.sqrt((distancex * distancex) + (distancey * distancey));
powerx = this._x - (distancex / distance) * magnet / distance;
powery = this._y - (distancey / distance) * magnet / distance;
forcex = (forcex + (homex - x0) / 2) / 1.66;
forcey = (forcey + (homey - y0) / 2) / 1.66;
this._x = powerx + forcex;
this._y = powery + forcey;
};
}
Re: Kod, a wersja flasha
: pn lip 02, 2007 2:20 pm
autor: Thorus
Super! Wielkie dzieki za pomoc
