c# - 如何让精灵在单人游戏中从一个位置到鼠标点击进行可见的移动?
问题描述
我正在制作一个火球,它正在移动到鼠标点击的位置。火球精灵已经移动到该位置,但我看不到火球飞行。我想看看,火球“飞”到那个位置?
这是我的monogame代码,用c#编写
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);
}
有人可以帮助我吗?我没有在其他问题上找到帮助。
解决方案
到目前为止,球正在立即移动到鼠标的位置。但现在它需要自行移动到鼠标位置。
假设“飞向鼠标”,您的意思是沿直线移动到鼠标位置。您可以尝试使用Vector2.Normalize
来决定它需要向鼠标移动的方向和角度。
推荐阅读
- google-apps-script - 点击消息框
- java - com.android.volley.NoConnectionError:java.net.ConnectException:连接被拒绝
- java - 从ant切换到maven后无法在tomcat上部署
- java - 无论如何,使用 rs.next() 加载 java 数组都会引发空指针错误。用控制台检查
- r - data.table 未正确过滤
- oauth-2.0 - “MalformedResponse:由于语音响应为空,无法将 Dialogflow 响应解析为 AppResponse”在 OAuth 帐户链接流程中
- python - 无头浏览器与 Youtube 一起使用
- javascript - Flow 中的联合数组类型。类型 A 中缺少属性,但类型 B 中存在
- angular - goBack 路由后重新加载选项卡视图(Ionic 4)
- ember.js - Ember:从导入的 mixin 中覆盖属性?