本文整理汇总了C#中FarseerPhysics.Dynamics.Body.ApplyTorque方法的典型用法代码示例。如果您正苦于以下问题:C# Body.ApplyTorque方法的具体用法?C# Body.ApplyTorque怎么用?C# Body.ApplyTorque使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FarseerPhysics.Dynamics.Body
的用法示例。
在下文中一共展示了Body.ApplyTorque方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MainWindow
public MainWindow()
{
_proc = HookCallback;
_hookId = SetHook(_proc);
//Application.Run();
_timer.Interval = 1;
_timer.Tick += _timer_Tick;
InitializeComponent();
_timer.Start();
_area = Screen.PrimaryScreen.WorkingArea;
_world = new World(new Vector2(0, 9.8f));
// Farseer expects objects to be scaled to MKS (meters, kilos, seconds)
// 1 meters equals 64 pixels here
ConvertUnits.SetDisplayUnitToSimUnitRatio(64f);
/* Circle */
// Convert screen center from pixels to meters
Vector2 circlePosition = ConvertUnits.ToSimUnits(new Vector2((float)_area.Width/2, (float)_area.Height/2));
Left = (float)_area.Width/2 - (Width/2);
Top = (float) _area.Height/2 - (Height/2);
// Create the circle fixture
_circleBody = BodyFactory.CreateCircle(_world, ConvertUnits.ToSimUnits(100 / 2f), 10f, circlePosition);
_circleBody.BodyType = BodyType.Dynamic;
_circleBody.ApplyTorque(500f);
// Create the ground fixture
_groundBody = BodyFactory.CreateRectangle(_world, ConvertUnits.ToSimUnits(_area.Width*4),
ConvertUnits.ToSimUnits(1f), 1f,
ConvertUnits.ToSimUnits(new Vector2(_area.Width/2, _area.Height)));
_groundBody.IsStatic = true;
_groundBody.Restitution = 0.8f;
_groundBody.Friction = 0.5f;
// Create east wall
_groundBody2 = BodyFactory.CreateRectangle(_world, ConvertUnits.ToSimUnits(1f),
ConvertUnits.ToSimUnits(_area.Height), 1f,
ConvertUnits.ToSimUnits(new Vector2(_area.Width * 2 - 50,
_area.Height)));
_groundBody2.IsStatic = true;
_groundBody2.Restitution = 0.8f;
_groundBody2.Friction = 0.5f;
}
示例2: Initialize
public void Initialize(Texture2D sprite, ProjectileType type, Player plr, Body b, Texture2D shadow)
{
B = b;
alreadyCollidedOnceOrMore = false;
shade = shadow;
foreach (var item in Game1.projectiles) {
B.IgnoreCollisionWith(item.B);
}
B.OnCollision += new OnCollisionEventHandler(B_OnCollision);
uint[] d = new uint[shade.Width * shade.Height];
shade.GetData(d);
Vertices v = PolygonTools.CreatePolygon(d, shade.Width, true);
Vector2[] a = v.ToArray();
h = ShadowHull.CreateConvex(ref a);
if (plr.direction == 1)
dir = 1;
lock (Game1.projectileLock)
Game1.lightingEngine.Hulls.Add(h);
// B.ApplyLinearImpulse(new Vector2(50, -10));
if (plr.direction == 1) {
B.Position = new Vector2(-plr.Position.X, plr.Position.Y + 1);
B.ApplyTorque(-250f);
B.LinearVelocity = new Vector2(-65, 7);
} else {
B.Position = new Vector2(-plr.Position.X, plr.Position.Y + 1);
B.ApplyTorque(250f);
B.LinearVelocity = new Vector2(65, 7);
}
Active = true;
position = ConvertUnits.ToDisplayUnits(-plr.Position);
texture = sprite;
Type = type;
Pelaaja = plr;
hitBox.Width = 17;
hitBox.Height = 17;
hitBox.X = (int)position.X;
hitBox.Y = (int)position.Y;
}