Skip to content

Commit

Permalink
Kivy/Android
Browse files Browse the repository at this point in the history
- soft card flip
  • Loading branch information
lufebe16 committed Dec 13, 2023
1 parent c5b2256 commit 7bc56fc
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions pysollib/kivy/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def moveBy(self, dx, dy):
class _OneImageCard(_HideableCard):
def __init__(self, id, deck, suit, rank, game, x=0, y=0):
_HideableCard.__init__(self, id, deck, suit, rank, game, x=x, y=y)
self.twoImage = True

fimage = game.getCardFaceImage(deck, suit, rank)
bimage = game.getCardBackImage(deck, suit, rank)
Expand All @@ -74,9 +75,18 @@ def __init__(self, id, deck, suit, rank, game, x=0, y=0):

aimage = LImageItem(
pos=(x, -y), size=self._face_image.size, game=game, card=self)
aimage.add_widget(self._back_image)
self._active_image = aimage
if self.twoImage:
from kivy.uix.relativelayout import RelativeLayout

imgcontainer = RelativeLayout()
imgcontainer.add_widget(self._back_image)
imgcontainer.add_widget(self._face_image)
aimage.add_widget(imgcontainer)
self._face_image.opacity = 0
else:
aimage.add_widget(self._back_image)

self._active_image = aimage
self.item = MfxCanvasImage(
game.canvas, self.x, self.y, image=aimage, anchor="nw")

Expand All @@ -85,8 +95,17 @@ def __init__(self, id, deck, suit, rank, game, x=0, y=0):
# y = self.yy

def _setImage(self, image):
self._active_image.clear_widgets()
self._active_image.add_widget(image)
if self.twoImage:
from kivy.animation import Animation
z = 0
t = 'in_quad'
if image == self._face_image:
z = 1
anim = Animation(opacity=z, t=t, d=0.35)
anim.start(self._face_image)
else:
self._active_image.clear_widgets()
self._active_image.add_widget(image)

def showFace(self, unhide=1):
# print ('card: showFace = %s' % self._face_image.source)
Expand Down

0 comments on commit 7bc56fc

Please sign in to comment.