cocos2d-python:Sprite与点的碰撞
本帖最后由 歌者文明清理员 于 2023-4-1 11:26 编辑非常简单,请 pygame 帮下忙就行了{:10_256:}
import cocos, pygame
collidepoint = lambda sprite, pos: pygame.Rect(sprite.x - sprite.width // 2, sprite.y - sprite.height // 2, sprite.width, sprite.height).collidepoint(pos)
不想作弊?好吧{:10_249:}
import cocos
def collidepoint(sprite, pos):
pos = tuple(pos)
x1, y1, w, h = sprite.x, sprite.y, sprite.width, sprite.height
x1 -= w // 2
y1 -= h // 2
for x in range(x1, x1 + w):
for y in range(y1, y1 + h):
if (x, y) == pos:
return True
return False
这样运行耗时间,还有一种:{:10_279:}
import cocos
collidepoint = lambda sprite, pos: (sprite.x - sprite.width / 2 <= pos < sprite.x + sprite.width / 2) and (sprite.y - sprite.height / 2, sprite.y + sprite.height / 2) 顶 没有鱼币,非求助就没人了是吧
没有鱼币,非求助就没人了是吧
Threebody1 发表于 2023-4-17 20:12
没有鱼币,非求助就没人了是吧
没有鱼币,非求助就没人了是吧
我很赞同{:10_266:}
页:
[1]