1

我正在尝试用谷歌搜索,但我找到了更多答案,现在我无法得到我想要的。

我有障碍物,首先我想将它设置为世界并围绕障碍物的中心旋转它,然后如果用户触摸屏并且它是自由拖动的,我想围绕他们身体的点旋转障碍物(正好围绕屏幕中心) .

我找到了一些带有旋转关节、固定 RJ、重新计算向量和矩阵的解决方案,但我没有帮助(或者只是我使用错误,我不确定)。我认为应该有一个简单的解决方案,我可以将障碍物的固定中心设置为精确点(屏幕中心),然后为我正在用对象旋转的身体属性旋转添加值。

这就是我加载障碍物的方式:

for (int i = 0; i < 5; i++)
{
       _obstacles[i] = BodyFactory.CreateRectangle(World, 2f, 0.2f, 1f);
       _obstacles[i].IsStatic = true;
       _obstacles[i].Restitution = 0.2f;
       _obstacles[i].Friction = 0.2f;
}
_obstacles[2].Position = new Vector2(3f, 2f);
_obstacles[3].Position = new Vector2(3.5f, 5f);
_obstacles[3].Rotation -= 0.8f;
_obstacles[4].Position = new Vector2(2f, 5f);
_obstacles[4].Rotation += 0.8f;

_obstacle = new Sprite(ScreenManager.Assets.TextureFromShape(_obstacles[0].FixtureList[0].Shape,
                                                                    MaterialType.Dots,
                                                                    Color.SandyBrown, 0.8f));

然后我有输入句柄,我想开始围绕屏幕中心的确切点旋转障碍物:

foreach (GestureSample gesture in input.Gestures)
            {
                if (gesture.GestureType == GestureType.FreeDrag)
                {
                    if ((gesture.Position.X - gesture.Position2.X) > 0)
                    {
                        foreach (Body obstacle in _obstacles)
                        {
                            obstacle.Rotation += 0.01f;
                        }
                    }
                    else if ((gesture.Position.X - gesture.Position2.X) < 0)
                    {
                        foreach (Body obstacle in _obstacles)
                        {
                            obstacle.Rotation += -0.01f;
                        }
                    }
                }
            }

感谢您的帮助,对不起,我在这方面是初学者。

4

1 回答 1

0

我改变了如何做到这一点,我没有单独制作每个障碍,但我为障碍(bordes)做了课程,看起来像这样:

public Maze(World world, GameplayScreen screen, Vector2 position)
        {

            _agentBody = BodyFactory.CreateBody(world, position);
            _agentBody.BodyType = BodyType.Dynamic;
            _agentBody.IsStatic = true;
            _agentBody.Restitution = 0.2f;
            _agentBody.Friction = 0.2f;

            _offset = ConvertUnits.ToDisplayUnits(1f);
            _agentBody.CreateFixture(new PolygonShape(PolygonTools.CreateRectangle(1f, 0.05f, new Vector2(0f, 1f), 0), 1f));
            _agentBody.CreateFixture(new PolygonShape(PolygonTools.CreateRectangle(1f, 0.05f, new Vector2(0f, -1f), 0), 1f));
            _agentBody.CreateFixture(new PolygonShape(PolygonTools.CreateRectangle(0.05f, 1f, new Vector2(1f, 0f), 0), 1f));
            _agentBody.CreateFixture(new PolygonShape(PolygonTools.CreateRectangle(0.05f, 1f, new Vector2(-1f, 0f), 0), 1f));   
            _screen = screen;

            //GFX
        AssetCreator creator = _screen.ScreenManager.Assets;
        _box = new Sprite(creator.TextureFromVertices(PolygonTools.CreateRectangle(1f, 0.05f),
                                                       MaterialType.Blank, Color.White, 1f));

    }

现在我有弹跳的问题,但那是另一回事,这个问题已经解决了。

于 2012-10-11T06:51:08.550 回答