Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 Gettling starling与box2d一起工作,与as3一起调试Draw_Actionscript 3_Box2d - Fatal编程技术网

Actionscript 3 Gettling starling与box2d一起工作,与as3一起调试Draw

Actionscript 3 Gettling starling与box2d一起工作,与as3一起调试Draw,actionscript-3,box2d,Actionscript 3,Box2d,这个话题以前有人提过,但我在网上找到的例子中似乎没有一个适合我!我正在尝试让starling与box2d一起工作,也为box2d调试绘图工作 我已经尝试了很多不同的方法,我的代码现在有点混乱,因为我的注释尝试了不同的“解决方案”组合。有人知道如何正确地完成这一切吗?如果有人能解释一下,我会非常高兴的 这是我最后一次尝试: 在我的创业课程中: package { import flash.display.Sprite; import flash.display.StageAlign; impor

这个话题以前有人提过,但我在网上找到的例子中似乎没有一个适合我!我正在尝试让starling与box2d一起工作,也为box2d调试绘图工作

我已经尝试了很多不同的方法,我的代码现在有点混乱,因为我的注释尝试了不同的“解决方案”组合。有人知道如何正确地完成这一切吗?如果有人能解释一下,我会非常高兴的

这是我最后一次尝试:

在我的创业课程中:

package {

import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
//import flash.events.Event;

import starling.core.Starling;
//import starling.display.Sprite;

import flash.events.Event;

[SWF(width="640", height="480", frameRate="60", backgroundColor="#000000")]

public class Startup extends Sprite {
    public static var mStarling:Starling;
    public static var debugSprite:Sprite;


    public function Startup() {
    //addChild ( new Stats() );

    super();

    //stage.align = StageAlign.TOP_LEFT;
    //stage.scaleMode = StageScaleMode.NO_SCALE;

    // create our Starling instance
    mStarling = new Starling(Game, stage);

    // set anti-aliasing (higher the better quality but slower performance)
    mStarling.antiAliasing = 1;

    mStarling.showStats = true;

    // start it!
    mStarling.start();


    stage.stage3Ds[0].addEventListener(Event.CONTEXT3D_CREATE, onContextCreated);
    }

    private function onContextCreated(e:Event):void{
        ////debug mode
//            debugSprite=new Sprite();
//            //addChild(debugSprite);
//          Starling.current.nativeOverlay.addChild(debugSprite);

        //var debugSprite:Sprite=new Sprite();
        addChild(debugSprite);
        (mStarling.stage.getChildAt(0) as Game).DebugDraw(debugSprite)

    }
我这样称呼debugdraw:

debugDraw(Startup.debugSprite);
下面是一个被大量注释掉的调试图:

  private function debugDraw(debugSprite:flash.display.Sprite):void {
    /*var worldDebugDraw:b2DebugDraw=new b2DebugDraw();
    //var debugSprite:flash.display.Sprite = new flash.display.Sprite();
    var debugSprite:Sprite = new Sprite();
    addChild(debugSprite);
    //mStarling.current.nativeOverlay.addChild(debugSprite);
    //worldDebugDraw.SetSprite(debugSprite);
//debugDraw.SetSprite(Starling.current.nativeOverlay); //DOESN'T SEEM TO WORK
            worldDebugDraw.SetDrawScale(worldScale);
            worldDebugDraw.SetFlags(b2DebugDraw.e_shapeBit|b2DebugDraw.e_jointBit);

            //worldDebugDraw.SetFillAlpha(0.0);
            //worldDebugDraw.SetAlpha(0.0);
            //visible
            worldDebugDraw.SetFillAlpha(0.8); //for testing
            worldDebugDraw.SetAlpha(1); //for testing

            world.SetDebugDraw(worldDebugDraw);*/

            var worldDebugDraw:b2DebugDraw = new b2DebugDraw();
            worldDebugDraw.SetSprite(debugSprite);
            world.SetDebugDraw(worldDebugDraw);

        }

DebudDraw使用一个经典的Flash精灵(出于某种原因,您会不断创建新精灵)。只应创建一个b2DebugDraw,并使用该精灵进行设置

斯塔琳假装拥有舞台和所有的展示列表,但事实并非如此。只需使用启动实例,甚至直接使用阶段本身,而无需经过Starling,这将避免一些混乱

正确的方法是:

public var debugSprite:Sprite;//no static var
开始什么

//don't start it!
mStarling.start();
你启动了一个无法启动的程序。此时,您正在尝试创建有效的Context3D,请耐心等待。拆下那条线

现在在onContextCreated中:

mStarling.start();//now you can start
debugSprite = new Sprite();//create your sprite
addChild(debugSprite);
var game:Game = mStarling.stage.getChildAt(0) as Game;//Game? somebody is following a tutorial ...
if(game)
{
     game.setDebug(debugSprite);//this is a new public method to create in Game
}
在方法setDebug的游戏中(使用一个参数Sprite):


就是这样,不要创建新的精灵,不要创建新的debugdraw,这就是您所需要的一切。

请定义“工作”。它可能不会显示调试绘图。
var worldDebugDraw:b2DebugDraw = new b2DebugDraw();
worldDebugDraw.SetSprite(myspriteparameter);
world.SetDebugDraw(worldDebugDraw);