Problem is that
Animation of kivy is not working perfectly.rotate_value_angle is not getting change.
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)
I was expecting that it will also change its angle. But it is just changing its pos_hint and size and also not giving any type of error.
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
class MonCard(ButtonBehavior, RotateBehavior, Image):
pass
Function by which I changed to MonCard
def change_to_moncard(self, card):
card.__class__ = MonCard
And you can see result
[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 <sdl2>
[INFO ] [GL ] OpenGL version <b'OpenGL ES 3.2 v1.r19p0-01rel0.###other-sha0123456789ABCDEF0###'>
[INFO ] [GL ] OpenGL vendor <b'ARM'>
[INFO ] [GL ] OpenGL renderer <b'Mali-G71'>
[INFO ] [GL ] OpenGL parsed version: 3, 2
[INFO ] [GL ] Texture max size <8192>
[INFO ] [GL ] Texture max units <16>
[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 <android> provider
[INFO ] [Base ] Start application main loop
198
241
114
359
324
51
254
133
[INFO ] [Base ] Leaving application in progress...
Thanks for you answer
As far as I understand, you drag and drop an image and expect it to rotate, try doing the following. First of all, Since the image is a widget, you can transform the matrix
with self.canvas.before:
PushMatrix()
self.rotate=Rotate(angle=0,axis=(0,0,1),origin=self.origin)
with self.canvas.after:
PopMatrix()
We've set Rotate value to it, now we can access it. And PushMatrix and PopMatrix need to import from kivy.graphics
anim=Animation(angle=val, duration=0.5)
anim.start(self.rotate)
Please note, this is a separate animation, also I hope that it will work, if anything writes to me, and I hope the translator translated everything correctly :)