使用QGraphicsScene和的QGraphicsView开始使用一个基于区块的游戏中的Qt区块、游戏中、QGraphicsScene、QGraphicsView

2023-09-07 13:42:56 作者:無你不成家

我要开始在Qt编程二维瓷砖为基础的游戏和阅读有关的QGraphicsScene和的QGraphicsView类,它们的目的是用于显示和处理大量的2D对象。

I'm going to start programming a 2D tile-based game in Qt and read about the QGraphicsScene and QGraphicsView classes which are intended for displaying and handling lots of 2D objects.

我的问题是,将它是有很多使用QGraphicsScene的瓷砖创造一个世界是否可行?我可以添加整个世界一下子瓷砖由瓷砖或者我应该尝试实施一些限制区中的位?我读过,QGraphicsScene可以处理千条,但在2D瓷砖地图可以轻松获得非常,非常大的(200×200地砖?没有那么多,但是这已经40,000个对象这是很多)。

My question is that will it be feasible to create a world with lots of tiles using QGraphicsScene? Can I add the whole world at once tile-by-tile or should I try to implement something to restrict the area a bit? I've read that QGraphicsScene can handle "thousands of items" but a 2D tile map can easily get really, really big (200x200 tiles? not that many, but that's already 40,000 objects which is a lot).

该地图也将是pretty的太多静态的,所以它可能是可能得出它作为一个大的位图,但是这真的是prevents您使用的所有花哨的东西在QGraphicsScene像处理鼠标点击的独立项目等等。最重要的是我要画的球员,在筹备等等,不会对准瓷砖电网。是否有一些优化工具和使用大量的静态对象和一些动态的在它们之上?

The map is also going to be pretty much static so it might be possible to draw it as one big pixmap but this really prevents you from using all the fancy stuff in QGraphicsScene like handling mouse clicks on independent items etc. On top of that I'm going to draw the player, the NPCs and so forth which will not be aligned to the tile grid. Are there some optimization stuff for using lots of static objects and some dynamic ones on top of them?

时使用QGraphicsScene和的QGraphicsView甚至一个好主意,在所有或者我应该尝试寻找里面的Qt替代或者不同的,更多的游戏化的图书馆吗?

Is using QGraphicsScene and QGraphicsView even a good idea at all or should I try to look for an alternative inside Qt or maybe a different, more game-oriented library?

在此先感谢

推荐答案

您应该使用的QGraphicsView。

You should use QGraphicsView.

借助 40000芯片诠释了Qt文档是你最好的例子密切检查。它涉及的大量元素,借鉴他们在多尺度和更大量的复杂性。

The 40,000 Chips int the Qt Documentation is your best example to closely examine. It deals with the complexity of large numbers of elements, drawing them at multiple scales and a lot more.

玩的例子,你会看到,所有的芯片其实占了很大的照片,如果你缩小,您可以选择和拖放多个芯片的任何观点,或者您也可以在足以看到一些放大文字单独的芯片上。这将需要时间去了解每一个部分,但是这是一个非常彻底的例子来看看。

Play with the example and you will see that all the chips actually make up a large photo if you zoom out and that you can select, and drag and drop multiple chips at any view, or you can zoom in enough to see some text on an individual chip. It will take time to understand each part, but this is a very thorough example to look into.

在 chips.cpp 源,它显示如何仍然可以通过使用LevelOfDetail或LOD变量switch语句基于断存储在样式选项转型的快速运行。

In the chips.cpp source, it shows how it can still run quickly by using a "LevelOfDetail" or lod variable switch statement based off of the transformation stored in a style option.

Qt的图形视图进行了优化做了很多的你已经在你的问题讲的东西,但它需要一段时间来了解如何处理它。

Qt Graphics View has been optimized to do a lot of the things you have talked about in your question, but it takes a while to understand how to approach it.

如果您仍然有与要使用,我将存储平铺布局上的硬盘和加载你需要的时候你需要他们的人,并删除那些你不需要关闭地图的大小问题现场是必要的。

If you are still having issues with the size of the map you want to use, I would store tile layouts on the harddrive and load the ones you need when you need them, and remove the ones you don't need off of the scene as necessary.

 
精彩推荐