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


C# b2World.ClearForces方法代码示例

本文整理汇总了C#中Box2D.Dynamics.b2World.ClearForces方法的典型用法代码示例。如果您正苦于以下问题:C# b2World.ClearForces方法的具体用法?C# b2World.ClearForces怎么用?C# b2World.ClearForces使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Box2D.Dynamics.b2World的用法示例。


在下文中一共展示了b2World.ClearForces方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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

        }
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:101,代码来源:ApplicationSprite.cs

示例2: StarlingGameSpriteWithPhysics


//.........这里部分代码省略.........
                            // time for syncframe!
                            raise_onsyncframe = true;

                            // does it actually help us? disabled for now
                            var dx = syncframesince - syncframeinterval;
                            syncframesince = 0;

                            // Error: raise_onsyncframe: { physicstime_elapsed_PRE = 275, dx = 75, physicstime_elapsed_POST = 0 }

                            physicstime_elapsed_PRE -= dx;
                            syncframeextra += dx;


                            // 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
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:67,代码来源:StarlingGameSpriteWithPhysics.cs

示例3: 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();

                };


        }
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:67,代码来源:ApplicationSprite.cs

示例4: N2b2World

        public b2World N2b2World(JObject worldValue)
        {
            b2World world = new b2World(jsonToVec("gravity", worldValue));

            world.SetAllowSleeping((bool)worldValue.GetValue("allowSleep"));
            world.ClearForces();
            //world.Set(worldValue.getBoolean("autoClearForces"));
            world.SetWarmStarting((bool)worldValue.GetValue("warmStarting"));
            world.SetContinuousPhysics((bool)worldValue.GetValue("continuousPhysics"));
            world.SetSubStepping((bool)worldValue.GetValue("subStepping"));

            readCustomPropertiesFromJson(world, worldValue);

            int i = 0;
            JArray bodyValues = (JArray)worldValue["body"];
            if (null != bodyValues)
            {
                int numBodyValues = bodyValues.Count;
                for (i = 0; i < numBodyValues; i++)
                {
                    JObject bodyValue = (JObject)bodyValues[i];
                    b2Body body = N2b2Body(world, bodyValue);
                    readCustomPropertiesFromJson(body, bodyValue);
                    m_bodies.Add(body);
                    m_indexToBodyMap.Add(i, body);
                }
            }

            // need two passes for joints because gear joints reference other joints
            JArray jointValues = (JArray)worldValue["joint"];
            if (null != jointValues)
            {
                int numJointValues = jointValues.Count;
                for (i = 0; i < numJointValues; i++)
                {
                    JObject jointValue = (JObject)jointValues[i];
                    if (jointValue["type"].ToString() != "gear")
                    {
                        b2Joint joint = j2b2Joint(world, jointValue);
                        readCustomPropertiesFromJson(joint, jointValue);
                        m_joints.Add(joint);
                    }
                }
                for (i = 0; i < numJointValues; i++)
                {
                    JObject jointValue = (JObject)jointValues[i];
                    if (jointValue["type"].ToString() == "gear")
                    {
                        b2Joint joint = j2b2Joint(world, jointValue);
                        readCustomPropertiesFromJson(joint, jointValue);
                        m_joints.Add(joint);
                    }
                }
            }
            i = 0;
            JArray imageValues = (JArray)worldValue["image"];
            if (null != imageValues)
            {
                int numImageValues = imageValues.Count;
                for (i = 0; i < numImageValues; i++)
                {
                    JObject imageValue = (JObject)imageValues[i];
                    Nb2dJsonImage image = j2b2dJsonImage(imageValue);
                    readCustomPropertiesFromJson(image, imageValue);
                    m_images.Add(image);
                }
            }
            return world;
        }
开发者ID:netonjm,项目名称:RubeLoader,代码行数:69,代码来源:Nb2dJson.cs


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