Set certain actions inside ui.animate to happen instantly
Webmaster4o last edited by
I think there should be a way to mark certain lines in a function that should not be animated when
ui.animateis called. For example, in my cover flow, I have all the frames sliding, but what if I want one frame to have its alpha set to 0 before it slides? The only way to do this is to break the animation into two parts with a function between, like
ui.animate(anim_1, duration=1.0) self.subviews.alpha = 0.0 ui.animate(anim_2, duration=1.0) self.subviews.alpha = 1.0
This seems awkward, because I'm really performing one animation, but I'm having to split it. Maybe that's not the best example, but there are certainly cases where it would be desirable to have instant actions within an animation that had to happen in the middle.
I think a possibility would be to add comments above lines that should not be animated, like
def anim(): view['button'].frame = (0,0,30,60) #ui.no_animate view['button2'].frame = (90, 140, 20, 10) view['slider'].alpha = 0.3
Where the animated lines are
view['button'].frame = (0,0,30,60)
view['slider'].alpha = 0.3
and only the second action is not animated. This is just one way to implement my idea.
JonB last edited by
IIRC, animate is not parsing your python code, it is basically looking at what changed in your object, then interpolating those attribs over time. so trying to use comments wont work like that.
note that the way you "broke up" the animation is not doing what you think. Animations happen asynchronously, so your second animation is happening at the same time as the first ( if you animate different properties) ir overwriting it (if you are animating the same attribute). Try changing the frame, then changing it back in badk to back calls, and you will see what i mean.
You should use
completionto chain together animations. If you want to do something instantly at the start, that is no different than just setting that param before you start the animation. Note that doing so will effectively cancel animation of that attribute if you are already animating that attribute.
If you want to change an attribute in the middle of an animation, kick off two animations at the same time, making us of the
delayargument..l in this way you could have alpha switch at the halfway point, or even have alpha animating at a different rate. ,
If you dont like a few lines on animate calls, you should write your own wrapper that takes in a few a functions and chains together an animation.
for instance, one could envision creating pseudo acceleration by chaining two or three animations, that have different velocities.