0
角度回転のみKivy角度例
は、私が理解したい最初の例で動作します。なぜ、アングルアニメーション呼び出しを使用した例と、もう一方が失敗するのか。
私が収集できることから、これはBuilder.load_stringと関係があります。
実施例
#working example
from kivy.lang import Builder
from kivy.base import runTouchApp
from kivy.uix.image import Image
from kivy.graphics import Rotate
from kivy.properties import NumericProperty
from math import atan2, degrees
from kivy.animation import Animation
Builder.load_string('''
<PlayerImage>:
canvas.before:
PushMatrix
Rotate:
angle: self.angle
axis: (0, 0, 1)
origin: self.center
canvas.after:
PopMatrix
''')
class PlayerImage(Image):
angle = NumericProperty(0)
def on_touch_down(self, touch):
Animation.cancel_all(self)
angle = degrees(atan2(touch.y - self.center_y,
touch.x - self.center_x))
Animation(center=touch.pos, angle=angle).start(self)
root = Builder.load_string('''
Widget:
PlayerImage:
source: 'images/example.png'
allow_stretch: True
keep_ratio: False
''')
runTouchApp(root)
非実施例
from kivy.lang import Builder
from kivy.base import runTouchApp
from kivy.uix.image import Image
from kivy.graphics import Rotate
from kivy.properties import NumericProperty
from math import atan2, degrees
from kivy.animation import Animation
class PlayerImage(Image):
angle = NumericProperty(0)
def on_touch_down(self, touch):
Animation.cancel_all(self)
angle = degrees(atan2(touch.y - self.center_y,
touch.x - self.center_x))
Animation(center=touch.pos, angle=angle).start(self)
root = Builder.load_string('''
Widget:
PlayerImage:
source: 'images/example.png'
allow_stretch: True
keep_ratio: False
canvas.before:
PushMatrix
Rotate:
angle: self.angle
axis: (0, 0, 1)
origin: self.center
canvas.after:
PopMatrix
''')
runTouchApp(root)
これは機能しません。エラーメッセージが出ますか? – user2314737
角度回転は最初の例でのみ変化します。どちらの例も有効です。 – xxLITxx