as3 starling usando box2d

I have a problem using DebugDraw in box2d when it is integrated in starling object.

var debugSprite:Sprite = new Sprite();
addChild(debugSprite);
var debugDraw:b2DebugDraw = new b2DebugDraw();
debugDraw.SetSprite(debugSprite);
debugDraw.SetDrawScale(30);
debugDraw.SetLineThickness( 1.0);
debugDraw.SetAlpha(1);
debugDraw.SetFillAlpha(0.4);
debugDraw.SetFlags(b2DebugDraw.e_shapeBit);
PhysicsCore.World.SetDebugDraw(debugDraw);  

In the code above I have problem using flash.display.sprite and even starling.core.Starling does anyone have solution?

preguntado el 08 de noviembre de 11 a las 15:11

What is your question? Any Errors? -

2 Respuestas

I know this threat is a bit old now, but I have just come across this problem myself. debugDraw.SetSprite() expects flash.display.Sprite. Starling uses starling.display.Sprite;

If you use flash.display.Sprite, then you can't add it to the stage!

Esta es una solución que encontré:

In the Main class:

mStarling = new Starling(Game, stage);
stage.stage3Ds[0].addEventListener(Event.CONTEXT3D_CREATE, onContextCreated);

private function onContextCreated(e:Event):void
{
   var debugSprite:Sprite=new Sprite();
   addChild(debugSprite);
   (mStarling.stage.getChildAt(0) as Game).setDebugDraw(debugSprite)
}

In the Game class:

public function setDebugDraw(debugSprite:flash.display.Sprite):void{

   var debugDraw:b2DebugDraw = new b2DebugDraw();
   debugDraw.SetSprite(debugSprite);
   _world.SetDebugDraw(debugDraw);

}

Note that you will need the most up to date version of Starling. 3 months ago they added the stage parameter to Starling, without it, it wont work.

This was my source: http://forum.starling-framework.org/topic/how-to-draw-2d-elements-for-box2d-debug-draw

Espero que esto ayude

Will

Respondido el 29 de diciembre de 11 a las 20:12

Also something to note here, adding a flash.display.Sprite above starling stage will slow down your application. To make full use of starling, make sure you remove it from the stage when you publish instead of just disabling it. - WillDonohoe

If you'd like Box2D to draw on the flash layer, you can do this:

debugDraw.SetSprite(Starling.current.nativeOverlay);

Respondido el 11 de enero de 14 a las 00:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.