コード例 #1
0
ファイル: SpriteBatchScreen.cs プロジェクト: zx8326123/LGame
 public PBody BindTexturePhysics(bool fix, SpriteBatchObject o,
                                 float density)
 {
     if (usePhysics)
     {
         PBody body = _manager.AddShape(fix, o.GetAnimation()
                                        .GetSpriteImage(), MathUtils.ToRadians(o.GetRotation()),
                                        density);
         if (body.Size() > 0)
         {
             body.Inner_shapes()[0].SetPosition(o.X() / _manager.scale,
                                                o.Y() / _manager.scale);
         }
         body.SetTag(o);
         CollectionUtils.Put(_Bodys, o, body);
         return(body);
     }
     else
     {
         throw new RuntimeException("You do not set the physics engine !");
     }
 }
コード例 #2
0
ファイル: SpriteBatchScreen.cs プロジェクト: zx8326123/LGame
        public override void Alter(LTimerContext timer)
        {
            for (int i = 0; i < keySize; i++)
            {
                ActionKey act = (ActionKey)keyActions.Get(i);
                if (act.IsPressed())
                {
                    act.Act(elapsedTime);
                    if (act.isReturn)
                    {
                        return;
                    }
                }
            }
            if (content.IsVisible())
            {
                ProcessEvents();
                content.UpdateNode(timer.GetMilliseconds());
            }
            if (usePhysics)
            {
                if (_dt < 0)
                {
                    _manager.Step(timer.GetMilliseconds());
                }
                else
                {
                    _manager.Step(_dt);
                }
            }
            if (follow != null)
            {
                if (usePhysics)
                {
                    _manager.Offset(follow.GetX(), follow.GetY());
                }
                foreach (TileMap tile in tiles)
                {
                    float offsetX = GetHalfWidth() - follow.GetX();
                    offsetX = MathUtils.Min(offsetX, 0);
                    offsetX = MathUtils.Max(offsetX, GetWidth() - tile.GetWidth());

                    float offsetY = GetHalfHeight() - follow.GetY();
                    offsetY = MathUtils.Min(offsetY, 0);
                    offsetY = MathUtils
                              .Max(offsetY, GetHeight() - tile.GetHeight());

                    SetOffset(tile, offsetX, offsetY);
                    tile.Update(elapsedTime);
                }
            }
            foreach (SpriteBatchObject o in objects)
            {
                if (usePhysics)
                {
                    PBody body = (PBody)CollectionUtils.Get(_Bodys, o);
                    if (body != null)
                    {
                        PShape shape    = body.Inner_shapes()[0];
                        float  rotation = (shape.GetAngle() * MathUtils.RAD_TO_DEG) % 360;
                        AABB   aabb     = shape.GetAABB();
                        o.SetLocation(_manager.GetScreenX(aabb.minX),
                                      _manager.GetScreenY(aabb.minY));
                        o.SetRotation(rotation);
                    }
                }
                o.Update(elapsedTime);
                if (updateListener != null)
                {
                    updateListener.Act(o, elapsedTime);
                }
            }
            Update(elapsedTime);
            Commits();
        }