- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在用 Java 开发一个小游戏,我正在重写玩家移动系统,使其不再基于网格。这是一个 2D 横向卷轴,我想要实现的是基本的玩家移动,这样当用户按下并按住右键时,玩家向右移动,左键也是如此。我遇到的问题是另一个类中的 Paint 组件在屏幕上绘制玩家的图像,位置 X 和 Y 存储在设置类中。然后一个 KeyListener 类在用户按下 Right 时获取,并添加到 X 值(对于 Left 也是如此,但每次减 1)。这会在屏幕上创建一个缓慢移动的角色,而我想要做的是让他移动得更快,但每次增加的幅度不会超过 1 像素,因为看起来他正在跳过像素(我已经尝试过)。
我想知道是否有更好的方法来解决这个问题,因为我使用的代码是最低限度的,我的结果将是一个平滑移动的播放器。
KeyListener 片段:
public void keyPressed(KeyEvent arg0) {
int key = arg0.getKeyCode();
if(key == 39) { // Right Key
Settings.player_pos_x++;
}else if(key == 37) { // Left Key
Settings.player_pos_x--;
}
main.Game.redo();
}
在屏幕上绘制用户:
g.drawImage(player_image, Settings.player_pos_x, Settings.player_pos_y, this);
感谢任何帮助,如果您需要更多信息或代码,请随时询问。
最佳答案
让我们再试一次:)
报价:http://msdn.microsoft.com/en-us/library/b367a457.aspx
Flicker is a common problem when programming graphics. Graphics operations that require multiple complex painting operations can cause the rendered images to appear to flicker or have an otherwise unacceptable appearance.
When double buffering is enabled, all paint operations are first rendered to a memory buffer instead of the drawing surface on the screen. After all paint operations are completed, the memory buffer is copied directly to the drawing surface associated with it. Because only one graphics operation is performed on the screen, the image flickering associated with complex painting operations is eliminated.
报价:http://docs.oracle.com/javase/tutorial/extra/fullscreen/doublebuf.html
Suppose you had to draw an entire picture on the screen, pixel by pixel or line by line. If you were to draw such a thing directly to the screen (using, say, Graphics.drawLine), you would probably notice with much disappointment that it takes a bit of time. You will probably even notice visible artifacts of how your picture is drawn. Rather than watching things being drawn in this fashion and at this pace, most programmers use a technique called double-buffering.
关于Java Paint 组件刷新率?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10252889/
我正在编写一个小应用程序供我自己使用,它将使用公开发布的 RSS 提要。 据我所知,协议(protocol)中没有订阅/发布机制;我需要定期让我的应用程序 HTTP-GET RSS 提要。 如果是这样
我正在使用 requestAnimationFrame 在我的游戏中绘制玩家。其中一名球员比其他人移动得更快。我和他核对了一下,他告诉我他的显示器有 120hz 的刷新率。我假设这意味着 has 可以
我正在使用 onTouch(View arg0, MotionEvent arg1)作为游戏输入。它返回 false 所以它没有被处理。在我运行 4.0.4 的 HTC HD2 上,这足以让播放器足够
是否所有 RSS 提要都支持 HTTP ETags/last-modified header 用于指示提要是否已更新? 对于不包含最后修改标题的提要,确定提要更新频率的最佳方法是什么? 我希望根据每个
几个月来,我一直在将应用程序上传到 Google Play。我已经在我所有的 ~30 个应用程序中添加了 Admob 横幅广告。我将在本月收到第一笔付款,我将在 1 月份收到“大笔”付款(+2000
过去几天我一直在研究 Estimote Beacons。我开始怀疑 iBeacon 的有效性,因为它们在确定 Beacon 位置时存在高延迟。 当您移动 2-3 米时,它需要几秒钟才能找到正确的位置。
我目前正在为我的大学研究项目开发 Android 应用程序。此应用程序应该能够读取附近 GSM 基站的 RSSI 级别。我编写了以下函数,它成功读取了附近小区的 RSSI 电平。我每 200 毫秒调用
代码如下: Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nInd
所以我正在为 DOS 提示符开发老式 ASCII 游戏,你问值得我花时间吗?我想说的是,它是怀旧的。无论如何,自从我重新开始并重新学习如何直接访问屏幕内存以来,我一直享受着很多乐趣,直到最近我的游戏刷
如果我以尽可能高的精度单独使用 CoreLocation,我会每秒或 1Hz 获得一次更新。但是,如果我有一个刷新率为 10Hz 的外部蓝牙连接 GPS 单元,我仍然只会在 1Hz 时收到来自 Cor
我正在研究高速率渲染帧(理想情况下接近最大监视器速率),我想知道是否有人知道我应该在哪个级别开始研究:内核/驱动程序级别(操作系统空间)? X11级? svgalib(用户空间)? 最佳答案 在现代计
我正在创建一个多显示器全屏 DXGI/D3D 应用程序。我正在枚举可用的输出和适配器,以准备创建它们的交换链。 使用 DXGI 的 IDXGIFactory::CreateSwapChain 创建我的
在大多数教程或建议中,60 fps 的值被列为应用程序要达到的最终刷新率。 IE。如果该应用能够以 60 fps 的速度持续提供用户体验,则没有更多改进空间。 但是,对于较新的设备,例如哪些 iPad
我是一名优秀的程序员,十分优秀!