我想加载图像,旋转(因为图像是垂直的)并在独立于旋转之后进行编码(连续向右移动)
我可以旋转图像并继续编码,但是此后图像将出现意外行为(它开始向上移动,而不是向右移动)
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.graphics import Rectangle, Rotate, Color
from kivy.clock import Clock
from kivy.graphics import PushMatrix, PopMatrix
class Trunk(Widget):
def __init__(self, **kwargs):
super().__init__(**kwargs)
print(self.size, self.center)
self.pos = 500, 500
self.size = 200, 100
with self.canvas.before:
PushMatrix()
Rotate(angle=90, axis=(0, 0, 1), origin=self.center)
self.rect = Rectangle(pos=self.pos, size=self.size)
self.bind(pos=self.update_rect)
with self.canvas.after:
PopMatrix()
def update_rect(self, *args):
self.rect.pos = self.pos
class Game(Widget):
pass
def update(self, dt):
self.children[0].x += .5
class TestApp(App):
def build(self):
game = Game()
trunk = Trunk()
game.add_widget(trunk)
Clock.schedule_interval(game.update, 1.0 / 60)
return game
TestApp().run()
我希望矩形向右移动(self.children [0] .x + = .5),因为我要增加x,
谢谢