【问题标题】:How can I make a sprite to do a visible moving from a position to a mouse click in monogame?如何让精灵在单人游戏中从一个位置到鼠标点击进行可见的移动?
【发布时间】:2019-11-09 13:52:41
【问题描述】:

我正在制作一个火球,它正在移动到鼠标点击的位置。 火球精灵已经移动到该位置,但我看不到火球飞行。 我想看看,火球“飞”到那个位置?

这是我用 c# 编写的monogame代码

protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                Exit();

            // TODO: Add your update logic here
            var CurrentMouseState = Mouse.GetState();
            PreviousMouseState = CurrentMouseState;
            if (CurrentMouseState.LeftButton == ButtonState.Pressed)
            {
                ballPosition = new Vector2(CurrentMouseState.X, CurrentMouseState.Y);

            }

            base.Update(gameTime);
        }

有人可以帮我吗? 我没有在其他问题上找到帮助。

【问题讨论】:

    标签: c# mouseevent sprite monogame


    【解决方案1】:

    到目前为止,球正在立即移动到鼠标的位置。但现在它需要自己移动到鼠标位置。

    假设“飞向鼠标”,您的意思是沿直线移动到鼠标位置。您可以尝试使用Vector2.Normalize 来决定它需要向鼠标移动的方向和角度。

    试试这里找到的答案:https://gamedev.stackexchange.com/a/7757/96707

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-02-13
      • 1970-01-01
      • 2019-08-02
      • 2014-10-09
      • 1970-01-01
      • 2014-10-04
      • 1970-01-01
      相关资源
      最近更新 更多