Search code examples
iosactionscript-3haxestarling-framework

Starling, Nape, Flash, Haxe Dillemma


I am building a game in Flash for iOS using the Starling Framework. I am also using Nape, a 2D Physics engine. The problem I am experiencing is a particular method on the Nape engine uses flash.display.DisplayObject, however, because I am using the Starling framework, I instead have to use starling.display.DisplayObject. It returns this error:

1067: Implicit coercion of a value of type flash.display:DisplayObject to an unrelated type starling.display:DisplayObject.

There is no way to adjust this method. The Nape engine is compiled into a .swc, which I am unable to edit. The engine is also open source, but it is done in Haxe, and I cannot figure out how to compile it once I have edited it.

The source can be downloaded here: http://deltaluca.me.uk/docnew/

I need to change all the flash.display.DisplayObject in the nape.utils.Debug class to starling.display.DisplayObject.

If you can lend me any advice I'd be really greatful.


Solution

  • Here is what I do, pretty simple. Let me know if you have any more questions.

    When creating the Space -typically when the scene is created:

    /**
     * Create debug drawing space to overlay on assets if flag enabled in Release config
     */
    if(Release.DEBUG_PHYSICS){
        _debug = new ShapeDebug(320*2, 480*2, 0x000000);
        _debug.drawConstraints = true;
        _debug.drawCollisionArbiters = true;
        var MovieClipDebug:MovieClip = new MovieClip();
        MovieClipDebug.addChild(_debug.display);
        Starling.current.nativeOverlay.addChild(MovieClipDebug);
    }
    

    When the stage is destroyed:

    if(Release.DEBUG_PHYSICS){
        _debug.clear();
        _debug = null;
    }
    

    When the graphical engine updates:

    /**
     * Update the positions of the depug layer
     */
    if(Release.DEBUG_PHYSICS){
        _debug.clear();
        _debug.draw(_space);
        _debug.flush();
        _debug.display.x = this.x;
        _debug.display.y = this.y;
        // handles camera zooming in/out
        _debug.display.scaleX = this.scaleX;
        _debug.display.scaleY = this.scaleY;
    }