- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我昨天在 XNA 中用视口(viewport)做了一些事情,但无法弄清楚为什么我使用的 Sprite 在更改位置时比我的视口(viewport)移动得更快。我觉得它可能与不同的值类型(int 与 float)有关,但有人愿意详细说明一下吗?
这是我使用的代码...
Viewport myViewport;
Texture2D t;
SpriteFont f;
Vector2 point = new Vector2(0, 0);
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
Keys[] pressedKeys = Keyboard.GetState().GetPressedKeys();
for (int i = 0; i < pressedKeys.Length; i++)
{
if (pressedKeys[i] == Keys.W)
{
point.Y--;
}
else if (pressedKeys[i] == Keys.A)
{
point.X--;
}
else if (pressedKeys[i] == Keys.S)
{
point.Y++;
}
else if (pressedKeys[i] == Keys.D)
{
point.X++;
}
}
myViewport.X = (int)point.X;
myViewport.Y = (int)point.Y;
GraphicsDevice.Viewport = myViewport;
// TODO: Add your update logic here
base.Update(gameTime);
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.White);
spriteBatch.Begin();
spriteBatch.Draw(t, new Vector2(point.X, point.Y), Color.White);
spriteBatch.End();
// TODO: Add your drawing code here
base.Draw(gameTime);
}
最佳答案
首先,您可能应该在 Draw 函数中设置视口(viewport)。其次,您应该确保您的视口(viewport)边界始终保持在屏幕上!
无论如何,它之所以这样移动是因为 SpriteBatch 的坐标系在视口(viewport)方面的客户空间。
换句话说,根据 SpriteBatch
,位置 (0,0) 是 GraphicsDevice.Viewport
的左上角。
这就是为什么您的 sprite 移动速度是您预期速度的两倍,因为您实际上是在执行两种不同的操作来修改其渲染位置。
关于c# - Sprite 位置比视口(viewport)移动得更快,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4987180/
我想检测鼠标何时离开顶部的视口(viewport)(可以说是向北)。我在网上搜了下How can I detect when the mouse leaves the window? .是一个好的开始
我有一个 HTML 元素,宽 1000 像素,高 850 像素(它实际上是一个 iFrame,在 canvas 标签上包含一个 HTML5 游戏,但我希望这不会有影响)。 我希望元素在平板电脑上呈现,
我正在创建一个 2D 引擎,我想实现对接,所以我需要创建一个视口(viewport)并将屏幕渲染为纹理。 为了渲染视口(viewport),我将帧缓冲区保存到一个 FrameBufferObject
大多数移动页面都提供元视口(viewport)尺寸,例如 出于 iphone 向后兼容的原因,这将在宽度上模拟 320px... 但是当我通过 javascript 检查时 window.screen
我有一个客户提供的宽度为 1440 像素的网站。客户要求我使用以下方法将视口(viewport)设置为 1440 像素对于桌面浏览器,小于 1440 像素的屏幕不显示滚动条。 它确实适用于移动设备、i
我刚刚读了一篇 nice article on viewport这给我留下了几个关于移动设备上的视觉视口(viewport)与布局视口(viewport)的问题。 the width and the
layout viewport和visual viewport的解释可以找到here . 我已阅读 here和 here那个应该使用 如果想针对移动设备优化网页。 我想了解这对横向模式下的 ipho
我想用javascript获取视口(viewport)宽度。但不是常见的虚拟视口(viewport)。我需要逻辑硬件视口(viewport),在我的情况下,它不是设置视口(viewport)元标记的选
我有一个 menu 元素,如果 menu 元素变得在视口(viewport)之外,我想固定到浏览器视口(viewport)的顶部由于滚动。从概念上讲,我的网页看起来类似于下面的示例 HTML,其中菜单
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 4 年前。 Improve this qu
我只包含了“main”的 HTML 代码,因为这是我希望能够通过媒体查询控制的部分。我希望内容只能在小于 480 像素的视口(viewport)上查看,但浏览器似乎隐藏了所有视口(viewport)尺
我不知道如何描述这个,所以最好的办法是链接一个例子:http://www.pascalvangemert.nl/#/profile 无论这个人对侧边栏菜单做了什么都很棒,我很想复制它。我试过检查,但我
我遇到了一页末尾有空白的问题。据我所知,没有元素占据空间。仅当视口(viewport)设置为特定宽度时才会出现该空间。例如,它出现在宽度 940 和 400 左右,但不是 550 或非常宽。 起初我以
iPhone/iPad 等移动设备的视觉视口(viewport)和布局视口(viewport)有什么区别? 网上查了很多资料,还是不清楚。 最佳答案 视觉视口(viewport)是当前显示在屏幕上的页
我正在使用这个元标记来设置移动浏览器上的视口(viewport)大小: 和这个 css 以确保较大的图像不会导致在较小的视口(viewport)上滚动: img { max-width: 95%;
这是针对平板电脑浏览器的,它使用相对于视口(viewport)宽度/高度的尺寸。为简单起见,假设横向。 我在一个全屏容器中有两个 div,就像提供的图像一样。他们有 position:absolute
我在 opengl 中创建了一个迷宫,并且正在尝试创建一个小 map 。为此,我想到在视口(viewport)内创建一个视口(viewport)。我有三种方法,一种用于创建墙壁,另一种用于创建地板,另
所以我有 2 个屏幕:一个级别选择屏幕,使用分辨率为 720 x 405 的 FitViewport,然后是一个游戏屏幕,使用分辨率为 480 x 270 的 FillViewport,按每米像素数
无论视口(viewport)的宽度如何,我都有一个图像幻灯片,我试图将其置于视口(viewport)的中心。如果视口(viewport)比图像宽,使用 margin: auto; 很容易实现,但是,当
我有一个元素,该元素具有从屏幕边缘底部弹出并循环向下弹出(虽然不是完全向下)的动画。下面的代码对此非常有用。但是,有一个问题。当浏览器全屏显示时,百分比占旧视口(viewport)大小而不是新视口(v
我是一名优秀的程序员,十分优秀!