I got this from Michael James Williams, I’m almost embarassed to mention this but, having any sort of Math.function call, especially Math.sqrt in my case, is extremely hazardous to your application. I simply applied his method. Its a bit of a face palm.

For determining distance, which is heavily used for collision detection, one traditionally finds the differences in x and y, and then squares them using Pythagora’s Theorem. The root value of those squared distances added together gives you the exact distance between two objects. So:

var dist:Number = Math.sqrt(dx*dx + dy*dy);
if(dist < 40){
//slow, but massive explosion
}

Compared to this:

var dist:Number = dx*dx + dy*dy;

if(dist < 40*40){
//quickly animated, but massive explosion
}

That’s all there is to it. A massive increase in speed was seen immediately, since I had a few of those slow Math.sqrt calls.

Embed Version:
Showing 2 notes
  1. vgreano posted this
Follow on Twitter
Subscribe via RSS
Follow on Tumblr
Drop me an Email

BOOM! So this is basically a playground for my projects, in which I strive to improve, or create new flash games.

I intend on using your feedback to improve these games, so go ahead and suggest ideas -- if they're awesome you should expect to see them soon buddy.

Read my Life Story

blog comments powered by Disqus