Logo Hardware.com.br
WilliamFoose
WilliamFoose Super Participante Registrado
601 Mensagens 1 Curtida

Criando uma aranha no flash.

#1 Por WilliamFoose 19/07/2007 - 19:13
Estou aqui com esse animação. é que lhe interessar.

Aparecerá uma aranha na tela.

Poe no flash resolução 1024 x 768.

Fundo branco.

coloque somente 1 layer e coloque este codigo.


function move() {
if (!this.beginX) {
this.beginX = this.shadow_x;
this.changeX = this.targetX - this.beginX;
this.beginY = this.shadow_y;
this.changeY = this.targetY - this.beginY;
}
this.shadow_x = Math.easeInOutQuad(this.time++, this.beginX, this.changeX, this._parent.duration);
this.shadow_y = Math.easeInOutQuad(this.time, this.beginY, this.changeY, this._parent.duration);
this.footHeight = _root.stepHeight * Math.sin(this.time / this._parent.duration * Math.PI);
this.x = this.shadow_x;
this.y = this.shadow_y - this.footHeight;
if (this.time > this._parent.duration) {
this.beginX = false;
this.time = 0;
delete this.onEnterFrame;
}
}
function walk() {
if (this._x > (Stage.width + _root.buffer)) {
this._x = -_root.buffer / 1.5;
this.resetMove();
}
if (this._x < -_root.buffer) {
this._x = Stage.width + _root.buffer / 1.5;
this.resetMove();
}
if (this._y > (Stage.height + _root.buffer)) {
this._y = -_root.buffer / 1.5;
this.resetMove();
}
if (this._y < -_root.buffer) {
this._y = Stage.height + _root.buffer / 1.5;
this.resetMove();
}
var totX;
var totY;
i = 1;
while (i <= _root.numLegs / 2) {
totX += this[("L" + i)].shadow_x;
totY += this[("L" + i)].shadow_y;
totX += this[("R" + i)].shadow_x;
totY += this[("R" + i)].shadow_y;
i++;
}
this._x = totX / _root.numLegs;
this._y = totY / _root.numLegs;
var aveX1 = (this.L4.shadow_x + this.R4.shadow_x) / 2;
var aveY1 = (this.L4.shadow_y + this.R4.shadow_y) / 2;
var bodyAngle = (Math.atan2((this._y - aveY1), (this._x - aveX1)) + Math.PI);
this.rear_x = this._x + 9 * Math.cos(bodyAngle);
this.rear_y = this._y + 7.2000000000000002 * Math.sin(bodyAngle);
this.rear2_x = this._x + 12.5 * Math.cos(bodyAngle);
this.rear2_y = this._y + 10 * Math.sin(bodyAngle);
if (this.counter == _root.wait) {
var currLeg = _root.walkCycle[this.leg].leg;
var legLength = _root.walkCycle[this.leg].length;
if ((int(Math.random() * 8) + 1) == 8 && currLeg.charAt(1) == "1") {
Math.round(Math.random()) ? (this.angle = this.angle - this.angleSpeed) : (this.angle = this.angle + this.angleSpeed);
this.angle = Math.fixAngle(this.angle);
}
this.leg < (_root.numLegs - 1) ? this.leg++ : (this.leg = 0);
currLeg.charAt(0) == "R" ? (this.side = -1) : (this.side = 1);
var legStride = (_root.stride - (currLeg.charAt(1) - 1) * _root.stride / (_root.numLegs / 3));
var dest_x = (this._x + Math.cos(this.angle * 0.017453292519943295) * legStride);
var dest_y = (this._y + Math.sin(this.angle * 0.017453292519943295) * legStride);
this[currLeg].targetX = dest_x + this.side * Math.sin(this.angle * 0.017453292519943295) * legLength;
this[currLeg].targetY = dest_y - this.side * Math.cos(this.angle * 0.017453292519943295) * legLength;
this[currLeg].onEnterFrame = move;
}
this.counter < _root.wait ? this.counter++ : (this.counter = 0);
}
Math.easeInOutQuad = function(t, b, c, d) {
if ((t = t / (d / 2)) < 1) {
return (c / 2 * t * t + b);
}
return (-c / 2 * (--t * (t - 2) - 1) + b);
};
Math.fixAngle = function(angle) {
angle %= 360;
return angle < 0 ? (angle + 360) : angle;
};
numWalkers = 1;
stride = 50;
legHeight = 8;
buffer = 50;
stepHeight = 6;
wait = 2;
walkCycle = new Array({leg:"R2", length:35}, {leg:"L1", length:25}, {leg:"L3", length:30}, {leg:"R4", length:25}, {leg:"R1", length:25}, {leg:"L2", length:35}, {leg:"R3", length:30}, {leg:"L4", length:25});
numLegs = walkCycle.length;
i = 1;
while (i <= _root.numWalkers) {
_root.createEmptyMovieClip(("body" + i), depth++);
j = 0;
while (j < _root.numLegs) {
_root[("body" + i)].createEmptyMovieClip(_root.walkCycle[j].leg, depth++);
_root[("body" + i)][_root.walkCycle[j].leg].length = _root.walkCycle[j].length;
j++;
}
_root[("body" + i)]._x = Math.random() * Stage.width;
_root[("body" + i)]._y = Math.random() * Stage.height;
_root[("body" + i)].angle = _root[("body" + i)]._rotation = Math.random() * 360;
_root[("body" + i)].resetMove = function() {
j = 1;
while (j <= _root.numLegs / 2) {
delete this[("R" + j)].onEnterFrame;
delete this[("L" + j)].onEnterFrame;
this[("R" + j)].beginX = false;
this[("L" + j)].beginX = false;
this[("R" + j)].time = 0;
this[("L" + j)].time = 0;
j++;
}
this.setLegs();
};
_root[("body" + i)].setLegs = function() {
var legAngle = 360 / (2 + _root.numLegs);
j = 1;
while (j <= _root.numLegs / 2) {
this[("R" + j)].shadow_x = this[("R" + j)].x = this._x - Math.sin(((this.angle - 90) + legAngle * j) * 0.017453292519943295) * this[("R" + j)].length;
this[("R" + j)].shadow_y = this[("R" + j)].y = this._y + Math.cos(((this.angle - 90) + legAngle * j) * 0.017453292519943295) * this[("R" + j)].length;
this[("L" + j)].shadow_x = this[("L" + j)].x = this._x + Math.sin(((this.angle + 90) - legAngle * j) * 0.017453292519943295) * this[("L" + j)].length;
this[("L" + j)].shadow_y = this[("L" + j)].y = this._y - Math.cos(((this.angle + 90) - legAngle * j) * 0.017453292519943295) * this[("L" + j)].length;
j++;
}
};
_root[("body" + i)].setLegs();
_root[("body" + i)].onEnterFrame = walk;
_root[("body" + i)].duration = 9 + int(Math.Random() * 4);
_root[("body" + i)].angleSpeed = 20 + int(Math.Random() * 10);
i++;
}
onEnterFrame = function () { _root.clear(); var i = 1; i = 1; while (i <= _root.numWalkers){ _root.lineStyle(8, 9934488, 20); _root.moveTo(_root[("body" + i)]._x, _root[("body" + i)]._y); _root.lineTo((_root[("body" + i)]._x + 0.5), _root[("body" + i)]._y); _root.lineStyle(13, 9934488, 20); _root.moveTo(_root[("body" + i)].rear_x, _root[("body" + i)].rear_y); _root.lineTo(_root[("body" + i)].rear2_x, _root[("body" + i)].rear2_y); _root.lineStyle(3, 9934488, 25); j = 1; while (j <= _root.numLegs / 2){ _root.moveTo(_root[("body" + i)][("R" + j)].shadow_x, _root[("body" + i)][("R" + j)].shadow_y); _root.lineTo(_root[("body" + i)]._x, _root[("body" + i)]._y); _root.moveTo(_root[("body" + i)][("L" + j)].shadow_x, _root[("body" + i)][("L" + j)].shadow_y); _root.lineTo(_root[("body" + i)]._x, _root[("body" + i)]._y); j++; } _root.lineStyle(1, 3355443, 100); j = 1; while (j <= _root.numLegs / 2){ _root.moveTo(_root[("body" + i)][("R" + j)].x, _root[("body" + i)][("R" + j)].y); _root.curveTo(_root[("body" + i)][("R" + j)].x, (_root[("body" + i)][("R" + j)].y - 15), _root[("body" + i)]._x, (_root[("body" + i)]._y - _root.legHeight)); _root.moveTo(_root[("body" + i)][("L" + j)].x, _root[("body" + i)][("L" + j)].y); _root.curveTo(_root[("body" + i)][("L" + j)].x, (_root[("body" + i)][("L" + j)].y - 15), _root[("body" + i)]._x, (_root[("body" + i)]._y - _root.legHeight)); j++; } _root.lineStyle(5, 3355443, 100); _root.moveTo(_root[("body" + i)]._x, (_root[("body" + i)]._y - _root.legHeight)); _root.lineTo((_root[("body" + i)]._x + 0.5), (_root[("body" + i)]._y - _root.legHeight)); _root.lineStyle(10, 7078411, 100); _root.moveTo(_root[("body" + i)].rear_x, (_root[("body" + i)].rear_y - _root.legHeight)); _root.lineTo(_root[("body" + i)].rear2_x, (_root[("body" + i)].rear2_y - _root.legHeight)); i++; } };



Lá no flash ela aparecerá embaralhada. Mas e só pô para alinhas as linhas. E funfa beleza.
© 1999-2024 Hardware.com.br. Todos os direitos reservados.
Imagem do Modal