|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 歌者文明清理员 于 2023-4-1 11:26 编辑
非常简单,请 pygame 帮下忙就行了
- 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)
复制代码
不想作弊?好吧
- 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
复制代码
这样运行耗时间,还有一种:
- import cocos
- collidepoint = lambda sprite, pos: (sprite.x - sprite.width / 2 <= pos[0] < sprite.x + sprite.width / 2) and (sprite.y - sprite.height / 2, sprite.y + sprite.height / 2)
复制代码 |
评分
-
查看全部评分
|