Python/kivy: анимация вращения не работаетPython

Программы на Python
Anonymous
Python/kivy: анимация вращения не работает

Сообщение Anonymous »

Проблема в том, что
анимация kivy работает не идеально. Rotate_value_angle не изменяется.

Код: Выделить всё

if not replaced:
if self.ids.battelground.collide_point(*touch.pos):
self.adjust_positions(card)
val = random.randint(0,360)
self.change_to_moncard(card)
print(str(val))
anim = Animation(pos_hint={'center_x': 0.5, 'center_y': 0.5}, size=(90, 100),rotate_value_angle = val,duration=0.5)
anim.start(card)

Я ожидал, что он тоже поменяет угол. Но он просто меняет свой pos_hint и размер, а также не выдает никаких ошибок.
DraggableCard

Код: Выделить всё

class DraggableCard(DragBehavior,Image):
def __init__(self, initial_pos_hint, w=100, h=150, **kwargs):
super().__init__(**kwargs)
self.size_hint = (None, None)
self.size = (w, h)  # Unique identifier for the card
self.initial_pos_hint = initial_pos_hint

def on_touch_down(self, touch):
if self.collide_point(*touch.pos):
self.drag_touch = touch
if self.parent:
self.parent.bring_to_front(self)
self.card_x_positions = sorted(widget.initial_pos_hint['center_x'] for widget in self.parent.children if isinstance(widget, DraggableCard))
return True
return super().on_touch_down(touch)

def on_touch_move(self, touch):
if hasattr(self, 'drag_touch') and touch is self.drag_touch:
parent_width = self.parent.width
parent_height = self.parent.height

new_center_x = self.center_x + touch.dx
new_center_y = self.center_y + touch.dy

self.pos_hint = {
'center_x': new_center_x / parent_width,
'center_y': new_center_y / parent_height
}

return True
return super().on_touch_move(touch)

def on_touch_up(self, touch):
if hasattr(self, 'drag_touch') and touch is self.drag_touch:
del self.drag_touch
if self.parent:

self.parent.handle_card_drop(self, self.card_x_positions, touch)
return True
return super().on_touch_up(touch)

Класс MonCard

Код: Выделить всё

class MonCard(ButtonBehavior, RotateBehavior, Image):
pass
Функция, с помощью которой я перешел на MonCard

Код: Выделить всё

 def change_to_moncard(self, card):
card.__class__ = MonCard

И вы можете увидеть результат

Код: Выделить всё

[INFO   ] [Logger      ] Record log in /storage/emulated/0/Documents/Pydroid3/Monster Card Mania/.kivy/logs/kivy_24-08-04_19.txt
[INFO   ] [Kivy        ] v2.2.1
[INFO   ] [Kivy        ] Installed at "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.11/site-packages/kivy/__init__.py"
[INFO   ] [Python      ] v3.11.4 (main, Sep 30 2023, 10:54:38) [GCC 11.4.0]
[INFO   ] [Python      ] Interpreter at "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/bin/python3"
[INFO   ] [Logger      ] Purge log fired. Processing...
[INFO   ] [Logger      ] Purge finished!
[INFO   ] [KivyMD      ] 1.2.0, git-Unknown, 2024-07-31 (installed at "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.11/site-packages/kivymd/__init__.py")
[WARNING] [KivyMD      ] Version 1.2.0 is deprecated and is no longer supported.  Use KivyMD version 2.0.0 from the master branch (pip install https://github.com/kivymd/KivyMD/archive/master.zip)
[INFO   ] [Factory     ] 190 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_pil (img_ffpyplayer ignored)
[INFO   ] [Text        ] Provider: sdl2
[INFO   ] [Window      ] Provider: sdl2
[INFO   ] [GL          ] Using the "OpenGL ES 2" graphics system
[INFO   ] [GL          ] Backend used 
[INFO   ] [GL          ] OpenGL version 
[INFO   ] [GL          ] OpenGL vendor 
[INFO   ] [GL          ] OpenGL renderer 
[INFO   ] [GL          ] OpenGL parsed version: 3, 2
[INFO   ] [GL          ] Texture max size 
[INFO   ] [GL          ] Texture max units 
[INFO   ] [Window      ] auto add sdl2 input provider
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
[INFO   ] [Clipboard   ] Provider: android
[INFO   ] [GL          ] NPOT texture support is available
[INFO   ] [Loader      ] using a thread pool of 2 workers
[WARNING] [Base        ] Unknown  provider
[INFO   ] [Base        ] Start application main loop
198
241
114
359
324
51
254
133
[INFO   ] [Base        ] Leaving application in progress...

Спасибо за ответ

Подробнее здесь: https://stackoverflow.com/questions/788 ... ot-working

Вернуться в «Python»