XNA:我点击过什么吗?
我正在 XNA 中制作游戏,目前我正在检查鼠标单击的坐标与每个可单击对象的坐标。
这对于我的小型游戏来说很好,但对于大型游戏来说,检查每个帧的每个对象将成为 CPU 密集型任务。
有更好的方法来解决这个问题吗?
I'm making a game in XNA and currently I'm checking the coordinates of the mouse click against the coordinates of each object that can be clicked.
This is fine for my small game but for larger games it would become CPU intensive to check through every object for each frame.
Is there a better way to approach this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将需要使用某种算法(例如 Quadtree)来划分您的世界空间。
在最基本的形式中,您将希望能够获取所有对象,并能够在进行详细检查之前快速扔掉其中一堆。例如,如果您单击屏幕右侧,您希望自动丢弃屏幕左侧的所有内容。
You will want to partition your world space with some sort of algorithm like Quadtree.
In your most basic form you'll want to be able to take all objects and be able to quickly throw out a bunch of them before you even do your detailed check. For instance, if you are clicking on the right side of the screen you want to throw out everything on the left side of the screen automagically.