如何在kivy中移动屏幕
How to move screen in kivy
我正在制作一个小游戏项目,并且正在努力让角色移动时屏幕跟随。更多细节,有带方向的按钮,点击播放器(widget class)移动,然后它离中间足够远,屏幕应该跟随(主要斗争部分)。
示例:
'''
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.widget import Widget
from kivy.lang.builder import Builder
Builder.load_string('''
<MainWin>:
Button:
text: "left"
size_hint: (0.2, 0.08)
pos_hint: {"x": 0.2, "y": 0.1}
on_press: root.move("left")
''')
class MainWin(FloatLayout):
def move(self, direction):
#when button is clicked
#all objects besides character moves the opposite way
pass
class MainApp(App):
def build(self):
return MainWin()
MainApp().run()
'''
改用RelativeLayout。然后如果你移动布局,里面的小部件也会移动。 FloatLayout的子元素使用绝对位置,RelativeLayout的子元素顾名思义使用相对位置。
我正在制作一个小游戏项目,并且正在努力让角色移动时屏幕跟随。更多细节,有带方向的按钮,点击播放器(widget class)移动,然后它离中间足够远,屏幕应该跟随(主要斗争部分)。
示例:
'''
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.widget import Widget
from kivy.lang.builder import Builder
Builder.load_string('''
<MainWin>:
Button:
text: "left"
size_hint: (0.2, 0.08)
pos_hint: {"x": 0.2, "y": 0.1}
on_press: root.move("left")
''')
class MainWin(FloatLayout):
def move(self, direction):
#when button is clicked
#all objects besides character moves the opposite way
pass
class MainApp(App):
def build(self):
return MainWin()
MainApp().run()
'''
改用RelativeLayout。然后如果你移动布局,里面的小部件也会移动。 FloatLayout的子元素使用绝对位置,RelativeLayout的子元素顾名思义使用相对位置。