开发者

Forcing re-sizing to be an odd multiple of 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 th开发者_如何转开发ese 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


You can check if something is odd by doing mod 2 to the number. So just do

if number mod 2 == 1:
   code for board


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:

Dim Height as Integer = SplitControl1.Panel1.Width
    If Height mod 8 <> 0 then
  Height -= (Height mod 8)
End If

Height += 9 //This ensures that the Height is not 0 and still is divisible by 8 + 1 (to be odd)

and

Dim Width as Integer = SplitControl1.Panel1.Width
If Width mod 8 <> 0 then
   Width -= (Width mod 8)
End If

Width += 9 //This ensures that the Width is not 0 and still is divisible by 8 + 1 (to be odd)

finally

SplitControl1.Panel1.Width = Width
SplitControl1.Panel1.Height = Height
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜