dcsimg
A Flash Developer Resource Site

Results 1 to 20 of 411

Thread: Optimization Tips

Threaded View

  1. #32
    hippie hater Cimmerian's Avatar
    Join Date
    Oct 2006
    Location
    over there
    Posts
    599
    Rigth, in the code you posted on that thread you showned that this circle to circle without sqrt you had the collisionRange pre calculated BEFORE any test,in this way
    Code:
    var collisionRange:Number = (heroRadius + enemyRadius) * (heroRadius + enemyRadius);

    now that makes sense and that is a lot diferent from this
    Code:
    function checkCollision(circle1, circle2) {
    circle1Radius = circle1._width>>1;
    circle2Radius = circle2._width>>1;
    xdist = circle2._x-circle1._x;
    ydist = circle2._y-circle1._y;
    return xdist*xdist+ydist*ydist<Math.pow(circle1Radius+circle2Radius, 2);
    }
    wich drops the sqrt but got to have a added step of find the pow of(circle1Radius + circle2Radius), so them becomes a matter of what is faster, pow vs sqrt
    And is also diferent to this,
    Code:
    var radius1 = (clip1._width * clip1._width)/2
    var radius2 = (clip2._width * clip2._width)/2
    var radius = radius1 + radius2
    wich seems a odd way to precalculate the collisionRange and gives an error, as i shown in the fla i have posted before
    So, again, for this to work you have to pre calculate all the combinations of summs of all radius, and even this will not be enough if you will have dynamic things with diferent sizes added at runtime...well...at first i was think it could be very dificult but now maybe you could just build a function that makes the calculation of that and put the result in a array and that is called whenever a new dynamic enemy is created, so it finds the new pow of the summ of the new radius plus any other radius and put on that array...
    Last edited by Cimmerian; 01-13-2007 at 06:04 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center