Calculate closest movie clip in Flash

Target Closest Enemy MovieClip

Wednesday, January 21st, 2009 | Game Engine, Game Examples AS2 | 5 Comments

I’ve been thinking about how targeting the closest enemy would work and started experimenting with the algorithm. Basically AS has an array method called sortOn, that sorts objects properties in any order you want. Well, that’s the catch. It only sorts objects, not movieClips.

The work around is simple enough; when creating a new enemy object, just save a reference to the movieClip on stage inside the object’s property.

Preview

Download Fla Sample

Download Fla Sample

Tags: , , , , , , , , , , ,