bai just read some of your codes and how you implimented it.
ang akong ma sulti hinya jud siya hehe even tried it on a 3gbp4 dual core 1.5gbram hinya jud.
Code:
function proximity() {
var x:Number = _root._xmouse;
var y:Number = _root._ymouse;
var cx:Number = this._x;
var cy:Number = this._y;
var prox:Number = Math.sqrt((x-cx)*(x-cx)+(y-cy)*(y-cy));
//prox = Math.ceil(prox);
//trace(prox);
//trace (flag)
if (prox<=10) {
hit = true;
} else {
hit = false;
}
}
onEnterFrame = function () {
proximity();
if (init == undefined) {
//get initial position
initx = this._x;
inity = this._y;
init = true;
//position added to reposition if the mouse is hovered on this object
ndy = y00+random(20);
ndy = Math.round(ndy);
ndx = x00+random(20);
ndx = Math.round(ndx);
}
//var hit = this.hitTest(_parent._xmouse, _parent._ymouse, true);
if (hit eq true) {
this._x += (this.dx-this._x)/6;
this._y += (this.dy-this._y)/7;
this.dx = ndx;
this.dy = ndy;
} else {
this._x += (this.dx-this._x)/6;
this._y += (this.dy-this._y)/6;
if (Math.round(this._y) == this.ndy) {
this.dx = initx;
this.dy = inity;
var x:Number = _root._xmouse;
var y:Number = _root._ymouse;
var cx:Number = this._x;
var cy:Number = this._y;
var xprox:Number = Math.sqrt((x-cx));
var yprox:Number = Math.sqrt((y-cy));
if (int(xprox)> 0 and int(xprox)<10) {
//trace ("right");
ndx = x00+random(30);
ndx = Math.round(ndx);
} else if (int(xprox)==0) {
//trace ("left");
ndx = x00-random(30);
ndx = Math.round(ndx);
}
if (int(yprox)> 0 and int(yprox)<10) {
ndy = y00+random(20);
ndy = Math.round(ndy);
} else if (int(xprox)==0) {
//trace ("left");
ndy = y00-random(20);
ndy = Math.round(ndy);
}
}
}
};
mao ni akong comments..
proximity();
cirular collision mani sakto?. sqrt functions takes so much time on cpu bai. you can use other functions nga mo detect og collision with
lesser cpu cycles. ithink its best to use square collision detection kai square bitaw imong objects.
if you still need circular collision bai u convert this vb function to fit your need..
xoffset1 = objectwidth/2
yoffset1 = objectheight/2
Code:
' Collision detection
Public Function CircleCD(x1 As Single, y1 As Single, xOffset1 As Single, yOffset1 As Single, Radius1 As Single, x2 As Single, y2 As Single, xOffset2 As Single, yOffset2 As Single, Radius2 As Single) As Boolean
Dim DeltaX As Single
Dim DeltaY As Single
Dim CD As Single
Dim SumRadii As Single
DeltaX = (x2 + xOffset2) - (x1 + xOffset1)
DeltaY = (y2 + yOffset2) - (y1 + yOffset1)
CD = (DeltaX * DeltaX) + (DeltaY * DeltaY)
SumRadii = Radius1 + Radius2
If (CD <= (SumRadii * SumRadii)) Then
CircleCD = True
Else
CircleCD = False
End If
End Function
basta avoid squareroot functions.. kai hinay kaau na.
as for the updating of x,y bai.. its best to use time based modeling.
kai tanaw nako sa imong script sigi man gud siya og update x,y nya di ra kaau ma notice ang movements. kai gagmay kaau og move or something
diri ma gamit nimo ang timebase modeling..
like if an object moves 5 pixels per second... then imo ra siya i update ang location sa pixel every 1second.. and not every time ma agi-an siya. (or dependi kanosa nimo gusto.. kong every 500ms raba or onsa).. mao rana akong ma suggest..
also bai if you can cache the variable i cache jud na kai you can save preciouse cpu cycles.
ex:
if(x-y)
if(x-y)
if(x-y != yy*yx)
if(x-y && yy*yx)
mas better if:
z = x-y
zz = yy*yx
if(z)
if(z)
if(z!=zz)
if(z&&zz)