Android:如何在网格上制作方形瓷砖夹

发布于 2025-01-07 01:15:37 字数 205 浏览 5 评论 0原文

我是 Android 编程新手,有一些问题。我正在尝试创建一个瓷砖拼图游戏,我必须将方形瓷砖移动到网格中,并且瓷砖会自动夹到适当的位置。例如,我有一个 3x3 的方形网格,有 9 个位置。每个位置的尺寸为 100x100 像素。如果我将一个图块(也是 100x100 像素)拖动到网格内 9 个位置中的任何一个,该图块会自动夹在 100x100 像素区域内的适当位置,即使它有点偏离。我该怎么做?

I'm new to android programming and have some questions. I'm trying to create a tile puzzle game where I have to move squared tiles into a grid and the tiles would automatically clip onto place. For example, I have a 3x3 squared grid with 9 position. Each position measures 100x100 pixel. If I drag a tile(also 100x100 pixel) to any of the 9 positions inside the grid, the tile would automatically clip in place inside the 100x100 pixel area even if it's a bit off. How do I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里人 2025-01-14 01:15:37
x=((int)(x/100))*100
y=((int)(y/100))*100

例如,如果 x=140 y=260 则

((int)(140/100))*100=100 
((int)(260/100))*100=200

由于 (int) ((int)(140/100)) 是 1 而不是 1.4,所以这样做的目的是将数字舍入

x=((int)(x/100))*100
y=((int)(y/100))*100

for example if you have x=140 y=260 then

((int)(140/100))*100=100 
((int)(260/100))*100=200

Because of the (int) the ((int)(140/100)) is 1 not 1.4 so the point of this is to round the number

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文