[英]How do I keep all my objects in my Java game the same across all monitors and resolutions?
I'm a beginner to java and I'm working on my first game :) 我是Java的初学者,正在从事我的第一个游戏:)
For my java game, do I need to position and size everything relative to my monitor settings? 对于我的Java游戏,是否需要相对于显示器设置来定位和调整所有内容? for instance 例如
to position and size things, I use Point(x,y) 定位和调整大小,我使用Point(x,y)
Shall I rather do "ScaledPoint" where "ScaledPoint" is equal to 我宁愿做“ ScaledPoint”,其中“ ScaledPoint”等于
public Point ScaledPoint(int x,int y)
{
return new Point(x*ScreenWidth/1680,y*ScreenHeight/1050);
}
Since my ScreenWidth and ScreenHeight as I'm developing the game world is 1680*1050 px? 由于我在开发游戏世界时的ScreenWidth和ScreenHeight是1680 * 1050 px?
To keep everything the same across different resolutions? 要在不同分辨率下保持相同? I'm not sure what to do. 我不知道该怎么做。
This is kind of a broad question, but a general principle would be to define your game space in some sort of device-independent coordinates with units small enough to accommodate your expected screen sizes and then some. 这是一个广泛的问题,但是一般的原则是使用与设备无关的某种坐标来定义您的游戏空间,其单位要足够小以容纳您期望的屏幕尺寸,然后再容纳一些。
Then, scale those coordinates for each display depending on the display size. 然后,根据显示器尺寸缩放每个显示器的坐标。 The scaling factor could possibly be something the user could configure. 比例因子可能是用户可以配置的。
The objective here is (as it is in many cases in computer science and software development) to separate the content from its presentation . 这里的目标是(因为在许多情况下在计算机科学和软件开发中)将内容与其表示分开。 You work internally in coordinates that are meaningful to you and consistent, and leave the layout on the screen to the presentation layer. 您在内部使用对您有意义且一致的坐标,然后将屏幕上的布局留给表示层。 This gives you the greatest flexibility and also simplifies the game engine programming since you're not worrying about display resolution at that level, only at the display level. 这使您具有最大的灵活性,并且简化了游戏引擎编程,因为您不必担心仅在显示级别上的该级别的显示分辨率。
This principle (separation of concerns) is why we moved from HTML-only in the web's prehistoric era (the 1990s), where HTML dictated both content and layout, to today's HTML+CSS where the HTML specifies the content and CSS can be used to present the information differently for different browsers. 这个原则(关注点分离)是为什么我们从Web的史前时代(1990年代)开始只使用HTML,HTML既规定内容和布局,又转移到今天的HTML + CSS,由HTML指定内容,而CSS可用于针对不同的浏览器呈现不同的信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.