简体   繁体   English

如何在所有监视器和分辨率下使Java游戏中的所有对象保持相同?

[英]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.

相关问题 如何使我的800 * 600游戏适合所有屏幕分辨率? - How to make my 800*600 game fit all screen resolutions? 如何将 Java 对象放入 HttpSession 并在我的所有包中使用它? - How do I put a Java object into a HttpSession and use it across all my packages? Java:获得一个/所有可用监视器(而不是整个桌面)的分辨率? - Java: Getting resolutions of one/all available monitors (instead of the whole desktop)? 如何在 JavaFX 中的所有场景中显示菜单栏 - How do i display my MenuBar across all my scenes in JavaFX 我的Java游戏中的MVC。 如何将对象连接到视图 - MVC in my java game. How do I connect the objects to the view 如何在所有活动中播放同一首歌 - How do i keep same song playing in all activities 如何将一个变量设置为在所有创建的相同类型的对象中相同? - How can I set a variable to be the same across all created objects of the same type? Java并发-使用信号量实现监视器-所有线程都陷入等待状态,我的理解有误 - Java Concurrency - Implementing Monitors using Semaphores - All threads getting stuck in waiting state, something wrong with my understanding Java-如何调整2D游戏的大小? - Java - how do I resize my 2D Game? 如何在 Java libGDX 中为我的游戏正确添加足迹 - How do i properly add footprints to my game in Java libGDX
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM