当前位置: 首页>>代码示例>>C#>>正文


C# Body.ApplyTorque方法代码示例

本文整理汇总了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;
        }
开发者ID:ptrandem,项目名称:DesktopGrenades,代码行数:48,代码来源:MainWindow.xaml.cs

示例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;
        }
开发者ID:aRkker,项目名称:Ninjapeli,代码行数:55,代码来源:Projectile.cs


注:本文中的FarseerPhysics.Dynamics.Body.ApplyTorque方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。