2017-05-03 27 views
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) 
+0

무엇이 작동하지 않습니까? 오류 메시지가 나타 납니까? – user2314737

+0

첫 번째 예제에서만 각도 회전이 변경됩니다. 두 예제 모두 작동합니다. – xxLITxx

답변

1

제 KVlang 블록 문체 상업적 과잉 회전에 압입 (및, 존재, 잘못된하는 누락 PushMatrix 이후의 ":").

+0

아주 단순한 실수 – xxLITxx