Mailing List
Home
Flash Pro
Extending Flash
Flash Macromedia Developer
Subjects
Firework Effect
setInterval bug identified and fixed
setInterval bug identified and fixed
ScrollPane component doesn 't auto update
Help: MX 2004 How to script a print button to print the entire sli
Event Dispatcher between classes
memory management removeMovieClip /
MX2004 Dataset itemClassName
Order of events per frame
XML to Object help
Textfield prototype question
Flash and QuickTime VR
Reading and displaying RSS feeds in Flash MX
Flash MX 2004 Sucks
AW: [Flashcoders] Switch/Case vs If/else
AW: [Flashcoders] Switch/Case vs If/else
Flash Interface with 10mb xml file
Web Service Results
Listener Object 's best practice
 
Search:  
Power your search with and, or, +, -, or "some phrase" operators.
How to optimize this code? (movement function)

How to optimize this code? (movement function)

2004-02-18       - By arzach

 Back
Reply:     1     2     3     4  

this code is part of a Component Window i 'm writing.
It 's a public method to move the object to a point, slowing down
(nothing new..)
My problem is that when lots of this function are fired the fps slow
down a lot. I tried to put the visibility off to found if it was the
code, and it is.

This functions it 's a bit strange because i need that the obj moves of
entires pixels (not 2.3 or 5.1) to avoid the blur of the rendering.
Doing so i must add just 1 pixel at time when the distance/fraction is
less than 1.

thank you in advance,
giorgio


public function slide(x:Number, y:Number, fraction:Number):Void {
this.mcSlideLoop.removeMovieClip();
var mcSlideLoop:MovieClip =
this.createEmptyMovieClip( "mcSlideLoop ",_depth++);
mcSlideLoop.onEnterFrame = function(Void):Void {
var dx:Number = x - _parent._x;
var dy:Number = y - _parent._y;
var ax:Number = dx/fraction;
var ay:Number = dy/fraction;
if (Math.abs(ax) <1) {
if (ax >0) ax = 1;
if (ax <0) ax = -1
}
if (Math.abs(ay) <1) {
if (ay >0) ay = 1;
if (ay <0) ay = -1
}
var tx:Number = _parent._x + ax;
var ty:Number = _parent._y + ay;
var check:Number = 0;
if (Math.abs(dx) <=1) check++;
if (Math.abs(dy) <=1) check++;
if (check==2) {
_parent.move(x,y);
_parent.onSlideComplete();
this.removeMovieClip();
} else {
_parent.move(Math.round(tx), Math.round(ty));
}

}
}



=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
Supported by Fig Leaf Software
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
Be sure to check the archives and the wiki:
http://chattyfig.figleaf.com/
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
http://chattyfig.figleaf.com/cgi-bin/ezmlm-cgi?1:mss:104671
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
To unsubscribe send a blank e-mail to:
Normal Mode: flashcoders-unsubscribe@(protected)
Digest Mode: flashcoders-digest-unsubscrive@(protected)