Interactive Objects

Issue #18 resolved
Chris Logsdon
created an issue

I had the idea of making an addInteractive() function in World that would be essentially the same as addDecal, but would have event:Event as an additional parameter. It would add something to the stage that would do something other than just "be there". A ladder would be an example of what this function would create, but I don't want to change how the ladders are made. Other things this would create would be: switches, moving platforms, etc.

Would we be better off making functions for each thing that comes up (addSwitch, etc)? Also, does giving a variable of type Event include ALL AS3 events, or is Event an actual type of event?

Comments (3)

  1. Jake Albano repo owner

    What we'd actually want to use is a function reference. Events are the worst programming pattern in Actionscript, and hilariously difficult to create custom types of. Passing a reference to a function that triggers when the player comes into contact with the object is probably the best way to go about this. In fact, I could extend the decal system to support this functionality.

  2. Jake Albano repo owner

    Implemented in revision 566687034b4c .

    Pass a reference to a function which takes an IfritObject as a parameter. If you don't want to set a callback function, set it to null.

    The addDecal function takes the same parameters.

    Game.stage.addChild(new Decal(Library.IMG("someDecal.png"), 100, 100, myFunction);
    private function myFunction(i:IfritObject):void
        if ( trace("Collision");
  3. Log in to comment