Flipping over a Card

By Posted February 16, 2008 13:53:51External Link
I'm trying to build a widget that looks like a playing card. When clicked I'd like it to change to look like the other side of the playing card. So far I have the back of the card, the cursor changes when I mouse over the card to the hand, but how do I then get the card to show the face image? Once flipped over how can I get it to flip back?
0 Karma 20 Replies 5 Referrals
February 16, 2008 14:06:02
Oooo, I did one of these a long time ago when I first started with DX. Will have a look through my archives.

Are you using two images or an animated png flip?
February 16, 2008 14:17:33
Two different images. I'm not certian how to do an animated .png flip yet. But I'd like to learn how.
February 16, 2008 14:24:13
RomanDA did a really cool flashcard thing a while back.  Probably no help here though. 
Sign Up or Login and this ad disappears!
There are many great features available to you once you register. Sign Up for a free account and browse the forums without ads.
February 16, 2008 14:41:55
Any ideas where I can find that?

February 16, 2008 14:57:45
Any ideas where I can find that?
http://romanda.wincustomize.com/skins.aspx?skinid=1074&libid=34

Text only, sorry.
February 16, 2008 15:18:07
That really works well. Now if I can just figure out how to do that for myself. I appreciate the pointer, Thanks.

February 16, 2008 15:47:43
Okay. My animation was old and needs some work.

The simplest method is to create two states. Name the first state back and the second state front.
Then use this code to change them.
Code: vbscript
  1. 'Called when L-click is released
  2. Function Object_OnLButtonUp(x, y, dragged)
  3. If Not dragged Then
  4. If Object.State= "back" Then
  5. Object.State="front"
  6. ElseIf Object.State="front" Then
  7. Object.State="back"
  8. End If
  9. End If
  10. End Function
February 16, 2008 16:39:16
OK, I understand the Front/Back portion, but where in the object do I specify what images are Front and Back?

February 16, 2008 17:11:04
In the states section. Instead of selecting a pre-existing state. Type your own.

Like this:
February 16, 2008 17:41:06
Hmmm, does it matter that I'm working as a shortcut? Do I need to be as a different object type? I cut and pasted your code into the script column and defined the "Front" and "Back" as directed. The front looks right but I'm unable to get it to look like the back. It does, however, execute the directed .exe command. On a different note...your Desktop X properties tool looks a lot different than mine.

February 16, 2008 17:46:00
Never mind, it helps when you spell things exactly as specified. Works like a charm, Thanks.
May 5, 2008 07:34:04
The above will give you an instant 'flip'. You could use an animated state to display a 'flipping' card image, but for a quick result which might work try this:

Sub animStateFlip(objName,newStateName)
If DesktopX.IsObject(objName) = False then Exit Sub

Set obj = DesktopX.Object(objName)
frames = 5
objLeftOriginal = obj.Left
objWidthOriginal = obj.Width
widthStep = objWidthOriginal/frames
For a = 1 to frames
newWidth = obj.Width - widthStep
obj.Width = newWidth
newLeft = obj.Left + widthStep/2
obj.Left = newLeft
Next
obj.Width = 0
obj.State = newStateName
For a = 1 to frames
newWidth = obj.Width + widthStep
obj.Width = newWidth
newLeft = obj.Left - widthStep/2
obj.Left = newLeft
Next
obj.Width = objWidthOriginal
obj.State = objLeftOriginal
End Sub

Call the function with the name of an object, and give it the state you want to change it to.
Increase the value of frames to make it slower and more smooth.

Could be adjusted in lots of ways.
Regards, Skarn
May 5, 2008 13:24:10
Nice one Skarn!

Here's the code to use what I posted above with Skarn's flip script.
Code: vbscript
  1. Function Object_OnLButtonUp(x, y, dragged)
  2. If Not dragged Then
  3. If Object.State= "back" Then
  4. Call animStateFlip(Object.Name,"front")
  5. 'Object.State="front"
  6. ElseIf Object.State="front" Then
  7. Call animStateFlip(Object.Name,"back")
  8. 'Object.State="back"
  9. End If
  10. End If
  11. End Function
May 5, 2008 13:57:14
Zubaz loves collaboration!
May 5, 2008 20:02:02
i was going to do a animated flip over on the Flash Card, but i wanted it faster than that.

Good suggestions all.
May 5, 2008 21:09:54
Nice script you guys!
May 5, 2008 21:47:35
i was going to do a animated flip over on the Flash Card, but i wanted it faster than that.Good suggestions all.


Maybe tray a Step Function with Object.Sleep. Messy but, it might be faster.

Here's one adapted for Top Flipping. You get another animation if you set your object width/height to "maintain aspect ratio".

Code: vbscript
  1. Function Object_OnLButtonUp(x, y, dragged)
  2. If Not dragged Then
  3. If Object.State= "back" Then
  4. Call animStateFlipH(Object.Name,"front")
  5. ElseIf Object.State="front" Then
  6. Call animStateFlipH(Object.Name,"back")
  7. End If
  8. End If
  9. End Function
  10. Sub animStateFlipH(objName,newStateName)
  11. If DesktopX.IsObject(objName) = False Then Exit Sub
  12. Set obj = DesktopX.Object(objName)
  13. frames = 5
  14. objTopOriginal = obj.Top
  15. objHeightOriginal = obj.Height
  16. heightStep = objHeightOriginal/frames
  17. For a = 1 To frames
  18. newHeight = obj.Height - heightStep
  19. obj.Height = newHeight
  20. newTop = obj.Top + heightStep/2
  21. obj.Top = newTop
  22. Next
  23. obj.Height = 0
  24. obj.State = newStateName
  25. For a = 1 To frames
  26. newHeight = obj.Height + heightStep
  27. obj.Height = newHeight
  28. newTop = obj.Top - heightStep/2
  29. obj.Top = newTop
  30. Next
  31. obj.Height = objHeightOriginal
  32. obj.State = objTopOriginal
  33. End Sub
May 6, 2008 08:59:37
need to add these to the snippets on the new site..

http://testsite.desktopx.info
May 7, 2008 04:53:20
reduce the number of frames to make it faster.

I don't think you could make it faster through any other code method, the way it's written it should do each change in width as fast as the computer possibly can.

You will note I don't have any obj.Width = obj.Width - widthAmount type commands, I found the double reference to an object in this way tended to be slower.

I am 'fairly' confident using a 'get property value to variable, adjust value of variable, reassign value to object property' was the fastest method.

SirSmiley, what is a step function?
May 7, 2008 12:46:28
Oops, not a function but, a step counter of sorts. Can't remember where I put it but, it actually would be slower in this situation.

Used it for animation control. If memory serves correctly the meat of it was this:
Code: vbscript
  1. Step 1
  2. Object.SetPicture="1.png"
  3. Object.Sleep 1000
  4. Step 2
  5. Object.SetPicture="2.png"
  6. Object.Sleep 5000


I think I opted to not use this but, replaced with a couple of timers and array's. One array for images and the second for the timer.
Stardock Forums v1.5.3112.18688
© 1995-2008 Stardock Corporation. All rights reserved.
All times are EST. The time is now 02:27:11
Server Load Time: 00:00:00   Page Render Time: