"""
pixelcollide像素级碰撞检测命令返回结果说明。
本例中返回的是r,的包括以下内容:
(hitx,hity),pixel1,pixel2,ret)
hitx,hity是相对于整个画布的碰撞点坐标
pixel1是主碰方,在这里是箭头在碰撞点的像素值
pixel2是被碰方,在这里是彩色方块在碰撞点的像素值
ret是两者重叠的矩形区域。
"""
from sprites import Sprite,mouse_pos,Mouse
arrow = Sprite('a.png')
cat = Sprite('square.png')
screen = cat.screen
leftkey = Mouse()
while True:
mx,my = mouse_pos()
arrow.goto(mx,my)
if leftkey.downup(): # 如果按下并松开
arrow.left(90)
r = arrow.pixelcollide(cat)
print(r)
|