Are you using two images or an animated png flip?
Text only, sorry.
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.
- 'Called when L-click is released
- Function Object_OnLButtonUp(x, y, dragged)
- If Not dragged Then
- If Object.State= "back" Then
- Object.State="front"
- ElseIf Object.State="front" Then
- Object.State="back"
- End If
- End If
- End Function
Like 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
Here's the code to use what I posted above with Skarn's flip script.
- Function Object_OnLButtonUp(x, y, dragged)
- If Not dragged Then
- If Object.State= "back" Then
- Call animStateFlip(Object.Name,"front")
- 'Object.State="front"
- ElseIf Object.State="front" Then
- Call animStateFlip(Object.Name,"back")
- 'Object.State="back"
- End If
- End If
- End Function
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".
- Function Object_OnLButtonUp(x, y, dragged)
- If Not dragged Then
- If Object.State= "back" Then
- Call animStateFlipH(Object.Name,"front")
- ElseIf Object.State="front" Then
- Call animStateFlipH(Object.Name,"back")
- End If
- End If
- End Function
- Sub animStateFlipH(objName,newStateName)
- If DesktopX.IsObject(objName) = False Then Exit Sub
- Set obj = DesktopX.Object(objName)
- frames = 5
- objTopOriginal = obj.Top
- objHeightOriginal = obj.Height
- heightStep = objHeightOriginal/frames
- For a = 1 To frames
- newHeight = obj.Height - heightStep
- obj.Height = newHeight
- newTop = obj.Top + heightStep/2
- obj.Top = newTop
- Next
- obj.Height = 0
- obj.State = newStateName
- For a = 1 To frames
- newHeight = obj.Height + heightStep
- obj.Height = newHeight
- newTop = obj.Top - heightStep/2
- obj.Top = newTop
- Next
- obj.Height = objHeightOriginal
- obj.State = objTopOriginal
- End Sub
http://testsite.desktopx.info
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?
Used it for animation control. If memory serves correctly the meat of it was this:
- Step 1
- Object.SetPicture="1.png"
- Object.Sleep 1000
- Step 2
- Object.SetPicture="2.png"
- 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.
Hi I am new at all this but learning. I want to try to do a flipping image. I understand I must create two objects, call one front and the other back. Questions: in which object do i add karn's flip script? And could someone tell me exactly where to put the name front and back in the script? Last, after this is done, do I group both objects (normal, optimized or combined)?
thanks for your help
You create one object with two states. See the picture in post nine.
You can rename states or enter a new state name when you click the add button.
WeatherBound is watching and Learning.
Thanks all![]()
SirSmiley, thank you, I tried it and it works.
I would like to now try to make an image (object) that slides open and shows something like digital time. Would someone know where I might find a tutorial or help doing this?
thanks for your time and help.
There are PLENTY of tutorials out there on all things DX
Startdock DesktopX Documentation
Click on Tutorials
another thing, try google'ing things like DesktopX Sliding, or DesktopX Tutorials you might be amazed all the things you find.
Welcome Guest! Please take the time to register with us.
- Richer content, access to many features that are disabled for guests like commenting and posting on the forums.
- Access to a great community, with a massive database of many, many areas of interest.
- Access to contests & subscription offers like exclusive emails.
- It's simple, and FREE!