问题描述
是否可以在 kivy 中检查两个图像是否重叠或碰撞?
我正在使用 ScreenManager,并且有一个我正在控制的动态图像。我想检查它是否发生碰撞,当发生碰撞时,我希望它的 pos 改变 (-) 负面。
我不知道要包含什么代码。但这里有一些有点相关。
Py 代码:
xnum = 0.53
ynum = 0.412
xmovement = 0.0889
ymovement = 0.05
movementt = 0.1
class L1(Screen):
screensize()
def animate_down_button(self,widget,*args):
global ynum
global ymovement
global movementt
ynum -= ymovement
anim = Animation(y_hint=ynum,duration=movementt)
anim.start(widget)
pass
def animate_up_button(self,*args):
global ynum
global ymovement
ynum += ymovement
anim = Animation(y_hint=ynum,duration=movementt)
anim.start(widget)
pass
def animate_right_button(self,*args):
global xnum
global xmovement
xnum += xmovement
anim = Animation(x_hint=xnum,duration=movementt)
anim.start(widget)
pass
def animate_left_button(self,*args):
global xnum
global xmovement
xnum -= xmovement
anim = Animation(x_hint=xnum,duration=movementt)
anim.start(widget)
pass
def play_nav(self):
if nav:
nav.play()
Kv 代码:
<L1>:
name: "L1"
canvas:
Rectangle:
source: 'background.jpg'
size: root.width,root.height
Rectangle:
source: 'Mazebg.png'
size: root.width*0.7,root.height*0.6
pos: root.width*0.5 - root.width*0.35,root.height*0.32
Rectangle:
source: 'Maze1.png'
size: root.width*0.7,root.height*0.32
Rectangle:
source: 'Star.png'
size: root.width*1.5,root.height*0.25
pos: (root.width*-0.125),root.height*0.92
Button:
pos_hint: {"x":0.01,"top":0.995}
size_hint: 0.15,0.075
background_normal: 'BackArrow.png'
background_down: 'BackArrowpressed.png'
on_release: root.play_nav()
on_release: app.root.current = "GameMenu"
Image:
id: mazeball
source: 'ball.png'
size_hint: 0.07,0.07
x_hint: 0.53
y_hint: 0.412
pos_hint: {"x": self.x_hint,"top": self.y_hint}
Button:
pos_hint: {"x":0.4,"top":0.17}
size_hint: 0.2,0.1
background_normal: 'PadDown.png'
background_down: 'PadDownpressed.png'
on_release: root.play_nav()
on_press: root.animate_down_button(mazeball)
Button:
pos_hint: {"x":0.4,"top":0.31}
size_hint: 0.2,0.1
background_normal: 'PadUp.png'
background_down: 'PadUppressed.png'
on_release: root.play_nav()
on_press: root.animate_up_button(mazeball)
Button:
pos_hint: {"x":0.525,"top": 0.235}
size_hint: 0.2,0.1
background_normal: 'padright.png'
background_down: 'padrightpressed.png'
on_release: root.play_nav()
on_press: root.animate_right_button(mazeball)
Button:
pos_hint: {"x":0.275,0.1
background_normal: 'PadLeft.png'
background_down: 'PadLeftpressed.png'
on_release: root.play_nav()
on_press: root.animate_left_button(mazeball)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)