Sunday, April 27, 2008

Mapper - API for mapping numeric properties

View SWF online
Download FLA
Download API

I came up with the question:
"What if I want to map a numeric property to another property through a linear relation?
And what if I make this relation constantly true all the time?"
So I made the Mapper API.

In fact, I was inspired by the minimap when playing Ratchet:Deadlocked today.
I made this API with in mind the purpose of implementing a minimap in a game.
Theoretically, Mapper can map a character's current position to a minimap displayed on the HUD.

Before you use Mapper,
call this static method first: Mapper.init(stage);
since Mapper depends on the Stage instance.
Then you can use Mapper.addTracker() to map one numeric property to another through a custom relation.

var mapper:Mapper = new Mapper();
mapper.addTracker(tracker, property, target, targetProperty, factor, scale, offset, preoffset);

After this mapper would maintain the following relationship:

tracker[property] = (target[targetProperty] + preoffset) * factor + offset;

No comments: