Interactive Objects

Chris Logsdon avatarChris 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

    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

    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 (Game.man.hitTestObject(i)) trace("Collision");
    }
    
  3. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.