强制调整大小为 8 的奇数倍
我有几个相互嵌套的分割面板。问题是,我正在中央面板内渲染 8x8 平铺游戏。基本上,面板的高度和宽度需要是 8 的奇数倍,这样我才能轻松找到显示的中心图块。
我正在使用 VB.net,所以所有 .net 解决方案都是可以接受的:)
编辑 抱歉,这有点令人困惑...
我的意思是,我需要宽度和高度能被 8 整除。数字 8 乘以应该是奇数:
再次编辑下面的这些数字并不涉及尺寸。它们指的是两个数字相乘。我已将它们更改为 * 以显示这一点。下面的这些数字适用于高度和宽度。一个数字应该是奇数,另一个数字应该是 8。 8*x
5*8 - 好
6*8 - 坏
I have a couple of split panels nested inside of each other. The problem is, I'm rendering an 8x8 tiled game inside of the center panel. Basically, the height and width of the panel need to be an odd multiples of 8 so I can find the center tile displayed easily.
I'm using VB.net so all .net solutions are acceptable :)
EDIT sorry, that was confusing a bit...
I mean, I need the width and height to be divisible by 8. The number 8 is multiplied by should be odd:
EDIT AGAIN these numbers below do not refer to the size. They refer to two number being multiplied. I've changed them to a * to show this. These numbers below apply to both the height and width. One number should be odd, the other 8. 8*x
5*8 - Good
6*8 - Bad
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过对数字执行 mod 2 来检查是否有奇数。所以就这样做
You can check if something is odd by doing mod 2 to the number. So just do
您说过您需要高度和宽度都可以被 8 整除,但在您的示例中只有高度可以被 8 整除。无论如何,这是一种方法:
将其放入调整大小事件处理程序中
最后
:
You stated that you need both the height and the width be divisable by 8 but in your example only height is divisible by it. anyway here's one way to do it:
place this into a resize event handler:
and
finally