- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在这里,我将两个图像一碰撞就卡住。 Lollipop 从左上角开始,小熊从右下角开始。他们在中间碰撞。我的位置告诉我,他们的距离更近了,不到50点
以下是 Lollipop 到熊的坐标距离: Lollipop [452, 320] 和熊[448, 330]
两者之间的距离:10.742572683895418
为什么情节告诉我的与我所看到的不同?为什么 Lollipop 的位置引用位于图像的底部,而熊位于图像的顶部?这是我如何位图传输图像。
rect = surface1.get_rect()
rect = rect.move(position[0]-rect.width//2, position[1]-rect.height//2)
screen.blit(surface1, rect)
图像的尺寸分别为(50,50)和(100,100)。
<小时/>如何让我的图像碰撞得比现在更近? (当蓝色背景接触时)
下面是当 Lollipop 从右侧来而从左侧来时它们如何碰撞。
这是它们从顶部/底部过来时如何碰撞 Lollipop [480, 291] 熊[440, 261]
距离:49.491213409963144
如何检查冲突:
def distance(p, q):
return math.sqrt((p[0]-q[0])**2 + (p[1]-q[1])**2)
最佳答案
如果我理解的话,您正在尝试将 Sprite 中心之间的距离与其中一个 Sprite 的大小进行比较。这对于矩形来说是不正确的。
首先,您使用的公式适用于圆。在这种情况下,您必须将距离与圆的组合半径进行比较。
对于矩形,您可以通过执行 Separating Axis Test 的最小形式来计算交集。 .
计算每个 Sprite 的最小和最大x
和y
边界,并将它们与每个 Sprite 的组合半尺寸进行比较:
halfWidthSprite1 = sprite1.width//2
halfWidthSprite2 = sprite2.width//2
halfHeightSprite1 = sprite1.height//2
halfHeightSprite2 = sprite2.height//2
distanceX = abs(sprite1.center[0] - sprite2.center[0])
distanceY = abs(sprite2.center[1] - sprite2.center[1])
collision = (distanceX < (halfWidthSprite1 + halfWidthSprite2)) and
(distanceY < (halfHeightSprite1 + halfHeightSprite2))
正如评论中提到的,您还可以使用内置 pygame.sprite.collide_rect实用程序。
关于python - Pygame 图像碰撞在视觉上留下图像之间的间隙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19826589/
目前,我在单击我的正文时打开一个新选项卡,但它将焦点更改为子窗口。但我想通过留下窗口来做到这一点,这样弹出窗口就不会被阻止,并且我可以将焦点放在当前窗口上。 以下代码当前正在运行 /** * For
我有一个带有线性渐变的 css 背景图像。 CSS 代码: .footer-about { display: flex; align-items: center; justif
在服务中包含以下代码(假设在快速端点上): async function (res, req, next) { const fetch = require('node-fetch'); awa
我正在使用 IImageList 和 SHGetFileInfo 为任何给定路径提取巨型图标。一旦我有了它,然后我使用 DrawIconEx 将 HICON 渲染到 HBITMAP 中,最终使用 GD
我有图表并计算了网络密度,现在我应该只保留具有最大权重的分支(网络密度的前 10%,例如 200 中权重最大的 20 个分支)。我找不到该怎么做? 最佳答案 这个问题有点令人困惑,因此,如果稍后出现更
我一直在尝试使用 jquery 创建一种效果,当您将鼠标移到一个 div 上时,整个 body 都会移动,并沿着它经过的点留下一条轨迹。我创建了一个可以使整个 body 移动的功能,但我找不到离开轨迹
我想在桌面上显示放大和缩小图标(控件),而仅在移动设备上浏览时显示 gps 图标。我正在使用这个 css https://unpkg.com/leaflet@1.1.0/dist/leaflet.cs
相关代码(索引为数组大小): typedef struct elemento { unsigned long linha; unsigned long coluna; doub
我有一个 div,因此当我单击时,它会切换为展开或缩回。它在所有浏览器上都运行良好,尽管有一点让我很感兴趣。在谷歌浏览器上,当它缩回时,它会在运动中留下细线。 www.rezoluz.com/logi
每当我的应用程序尝试通过调用 CreateDIBSection() 或使用 LR_CREATEDIBSECTION 标志调用 LoadImage() 来创建 DIB 部分时,它似乎都会成功返回。它返回
我想在 Protractor 测试中脱离 Selenium 控制流。 以下是我迄今为止遇到的步骤和问题: 1。逐个测试禁用它 我的第一个想法是使用 SELENIUM_PROMISE_MANAGER 以
我正在构建一个部署在 CentOS 7.2 上的 ASP.Net Core (netcore 1.1) 应用程序。 我有一个通过 System.Diagnostics.Process 调用外部进程(也
我正在为我的网站创建一个聊天小部件。用户将能够输入纯文本 - 没有 html。 为了消除 HTML 标记并允许用户使用“”,我正在接受他们的输入并在用户屏幕的输入上使用 strip_tags() 和输
我是一名优秀的程序员,十分优秀!