Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Tentei adaptar esse código, mas o movieclip não se move pela tela, tem uma diferença de visualização, não funciona com os mesmos números no AS3, tem alguma alteração do as2?
Tem outra forma de fazer esse calculo?
AS2
for (var i = 0; i < 250; i++)
{
var nm = "star" + i;
_root.attachMovie("star", nm, i);
_root[nm]._x = Math.random() * 550;
_root[nm]._y = Math.random() * 400;
_root[nm].distance = Math.random() * 200 + 1;
_root[nm]._xscale = 1000 / _root[nm].distance;
_root[nm]._yscale = 1000 / _root[nm].distance;
_root[nm].speed = 20 / _root[nm].distance;
_root[nm].onEnterFrame = function() this._x += this.speed;
if (this._x > 550) this._x = 0;
}
}
AS3
var stageWidth:Number = stage.stageWidth;
var stageHeight:Number = stage.stageHeight;
//var speed = 10;
for (var i = 0; i < 250; i++)
{
var bola = new Star();
addChild(bola);
bola.x = Math.random() * stageWidth - 10;
bola.y = Math.random() * stageHeight - 10;
bola.distance = Math.random() * 500 + 1;
bola.scaleX = 25 / bola.distance;
bola.scaleY = 25 / bola.distance;
bola.speed = 500 / bola.distance;
trace(this.speed);
bola.addEventListener(Event.ENTER_FRAME, EnterFrame);
function EnterFrame(e:Event):void{
this.x += this.speed;
if (this.x > stageWidth) this.x = 0;
}
}Carregando comentários...