本文整理汇总了C#中Box2D.Dynamics.b2World.DrawDebugData方法的典型用法代码示例。如果您正苦于以下问题:C# b2World.DrawDebugData方法的具体用法?C# b2World.DrawDebugData怎么用?C# b2World.DrawDebugData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Box2D.Dynamics.b2World
的用法示例。
在下文中一共展示了b2World.DrawDebugData方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplicationSprite
// http://blog.allanbishop.com/box2d-2-1a-tutorial-part-1/
public ApplicationSprite()
{
_world = new b2World(new b2Vec2(0, 10), true);
var groundBodyDef = new b2BodyDef();
groundBodyDef.position.Set(SWF_HALF_WIDTH / PIXELS_TO_METRE,
SWF_HEIGHT / PIXELS_TO_METRE - 20 / PIXELS_TO_METRE);
var groundBody = _world.CreateBody(groundBodyDef);
var groundBox = new b2PolygonShape();
groundBox.SetAsBox(SWF_HALF_WIDTH / PIXELS_TO_METRE,
20 / PIXELS_TO_METRE);
var groundFixtureDef = new b2FixtureDef();
groundFixtureDef.shape = groundBox;
groundFixtureDef.density = 1;
groundFixtureDef.friction = 1;
groundBody.CreateFixture(groundFixtureDef);
var bodyDef = new b2BodyDef();
bodyDef.type = b2Body.b2_dynamicBody;
bodyDef.position.Set(SWF_HALF_WIDTH / PIXELS_TO_METRE, 4);
var body = _world.CreateBody(bodyDef);
var dynamicBox = new b2PolygonShape();
dynamicBox.SetAsBox(1, 1);
var fixtureDef = new b2FixtureDef();
fixtureDef.shape = dynamicBox;
fixtureDef.density = 1;
fixtureDef.friction = 0.3;
body.CreateFixture(fixtureDef);
var debugSprite = new Sprite();
addChild(debugSprite);
var debugDraw = new b2DebugDraw();
debugDraw.SetSprite(debugSprite);
debugDraw.SetDrawScale(PIXELS_TO_METRE);
debugDraw.SetLineThickness(1.0);
debugDraw.SetAlpha(1);
debugDraw.SetFillAlpha(0.4);
debugDraw.SetFlags(b2DebugDraw.e_shapeBit);
_world.SetDebugDraw(debugDraw);
// Add event for main loop
this.stage.enterFrame +=
delegate
{
var timeStep = 1 / 30.0;
var velocityIterations = 6;
var positionIterations = 2;
_world.Step(timeStep, velocityIterations, positionIterations);
_world.ClearForces();
_world.DrawDebugData();
};
}
示例2: ApplicationSprite
//.........这里部分代码省略.........
{ Keys.Right, false },
{ Keys.Down, false },
}; //keep track of what keys are held down by the player
this.stage.keyDown +=
e =>
{
Console.WriteLine("keyDown " + new { e.keyCode });
KEYS_DOWN[(Keys)e.keyCode] = true;
};
this.stage.keyUp +=
e =>
{
Console.WriteLine("keyUp " + new { e.keyCode });
KEYS_DOWN[(Keys)e.keyCode] = false;
};
#region tick
Action<double> tick = (msDuration) =>
{
frameid++;
//if (frameid > 1)
// return;
//Console.WriteLine(new { frameid });
//GAME LOOP
//handle events. Key status (depressed or no) is tracked in via KEYS_DOWN associative array
//gamejs.event.get().forEach(function(event){
// //key press
// if (event.type === gamejs.event.KEY_DOWN) KEYS_DOWN[event.key] = true;
// //key release
// else if (event.type === gamejs.event.KEY_UP) KEYS_DOWN[event.key] = false;
//});
//set car controls according to player input
if (KEYS_DOWN[Keys.Up])
{
car.accelerate = ACC_ACCELERATE;
}
else if (KEYS_DOWN[Keys.Down])
{
car.accelerate = ACC_BRAKE;
}
else
{
car.accelerate = ACC_NONE;
}
if (KEYS_DOWN[Keys.Right])
{
car.steer = STEER_RIGHT;
}
else if (KEYS_DOWN[Keys.Left])
{
car.steer = STEER_LEFT;
}
else
{
car.steer = STEER_NONE;
}
////update car
car.update(msDuration);
//update physics world
b2world.Step(msDuration / 1000.0, 10, 8);
//clear applied forces, so they don't stack from each update
b2world.ClearForces();
//fill background
//gamejs.draw.rect(display, '#FFFFFF', new gamejs.Rect([0, 0], [WIDTH_PX, HEIGHT_PX]),0)
//let box2d draw it's bodies
b2world.DrawDebugData();
//fps and car speed display
//display.blit(font.render('FPS: '+parseInt((1000)/msDuration)), [25, 25]);
//display.blit(font.render('SPEED: '+parseInt(Math.ceil(car.getSpeedKMH()))+' km/h'), [25, 55]);
//Console.WriteLine(new { frameid } + " done!");
};
////gamejs.time.fpsCallback(tick, this, 60);
var sw = new Stopwatch();
sw.Start();
this.enterFrame +=
delegate
{
tick(sw.ElapsedMilliseconds);
sw.Restart();
};
#endregion
}
示例3: StarlingGameSpriteWithPhysics
//.........这里部分代码省略.........
// dropping frames?
//syncframeextra = Math.Min(syncframeextra, syncframeinterval);
}
#endregion
var iterations = 10;
syncframetime += physicstime_elapsed_PRE;
#region PRE Step
//update physics world
ground_b2world.Step(physicstime_elapsed_PRE / 1000.0, iterations, iterations);
groundkarma_b2world.Step(physicstime_elapsed_PRE / 1000.0, iterations, iterations);
air_b2world.Step(physicstime_elapsed_PRE / 1000.0, iterations, iterations);
damage_b2world.Step(physicstime_elapsed_PRE / 1000.0, iterations, iterations);
smoke_b2world.Step(physicstime_elapsed_PRE / 1000.0, iterations, iterations);
#endregion
ground_b2world.ClearForces();
groundkarma_b2world.ClearForces();
air_b2world.ClearForces();
damage_b2world.ClearForces();
smoke_b2world.ClearForces();
#region DrawDebugData ClearForces
if (!disablephysicsdiagnostics)
{
ground_b2world.DrawDebugData();
groundkarma_b2world.DrawDebugData();
air_b2world.DrawDebugData();
damage_b2world.DrawDebugData();
smoke_b2world.DrawDebugData();
}
#endregion
// syncframe
if (raise_onsyncframe)
{
syncframeid++;
this.onsyncframe(stage, s);
foreach (var item in units)
{
item.FeedKarma();
}
}
#region air_dd vs ground_dd
if (current != null)
if (current.body.GetWorld() == air_b2world)
{
air_dd.alpha = 0.6;
ground_dd.alpha = 0.1;
}
else
{
air_dd.alpha = 0.1;
ground_dd.alpha = 0.6;
}