I have an object in a Movieclip that I currently have a tween set up for. I set it up on the stage, not with actionscript.
I need to dynamically change the duration of this tween. I have not found reference to a way to do this.
I don't mind dynamically creating the tween if I need to, setting the initial duration in code, but I still have not found any reference to changing the duration dynamically.
Is this possible?
I'm just learning as3, so sorry if this is something that should be obvious.
I strongly suggest you to switch to TweenLite/TweenMax library, it's awesome, free, super-easy to use and it will change the way you work!
Have a look here, and here on the forum there's an explanation on how to change duration dynamically
Ideally you'd do it by programming the tween, there are many libraries out there that make it quite easy.
One of the ones I use frequently is eaze-tween, it has a timeline tween function, though I haven't used it, it is worth a try. eaze(target).to(duration, { frame:"label" });
Grant Skinner's gtween library also seems to be able to that using the GTweenTimeline Class.
The other thing you can do is modify the frame the animation is at at a varied rate, so to speed it up you'd go through it two frames at a time, so twice as fast. This way makes it limited to multiples of speed.
If you want to have more control there you'd need to have a longer tween, otherwise you might notice movement that is not very smooth. The way to do that would be to have a transition of a 100 frames, and use a tweening library, where the on update makes the value of the tween(which is a number between 0 and 1) and multiply it by the number of frames(100) and update the frame mc.gotoAndStop(int(val*100);. You can then assign various tweening functions and durations.
hope it helps
Related
I am new to libGDX. I am trying to move a sprite from one point to another by changing the x and y of the rectangle. Can I do this gradually ?
I am currently using this to set new co-ordinates
batch.draw(bucketCyan, bucket.x, bucket.y);
What you're talking about is called interpolation, and there are a bunch of different ways to do it. You can either update the variables yourself using the approach noone commented with, or you can check out the Interpolation class: http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/math/Interpolation.html
Google Universal Tween Engine. It's an easy to use interpolation "engine". It lets you modify or interpolate any values over time. It is easy to use and works well. It's worth spending some time to get familiar with.
Since I don't know english very well, I'm not able to find clear examples and/or tutorials for what I'm trying to do.
So the (maybe stupid) question is:
How can I strongly customize tweens using Starling framework and make my Sprites(or MovieClips) following a line, curve or create every other non-linear movement that doesn't exist in Transition Class?
I have no problem with Basic Starling animation. So it should be a good start point.
Thanks in advance for examples, resources or suggestions.
PS. I already visit the "Starling Wiki" page about custom Transitions but, as a Beginner(almost Intermediate) coder I wasn't able to completely understand it.
I know there are many online resources about AS3/Starling/Flash/Nape/Box2D but it's not easy for a non-english Beginner programmer to understand them.
You can simple move Starling's movieClip by set .x .y .rotation
Since now, I haven't heard of scripted transition to make predefined non linear movement. As you said, you can move object from one position to another, but it won't happen in a curved line.
What I've done in the past is to predefine the path of the movement, as I needed exactly the same weird path. I did a path tween in Flash, then used one simple function to loop through all frames (using gotoAndStop()) and getting x and y property of the object, storing them in an array. This was done when initializing. Later on I could start animation on all my weird paths whenever I wanted, using onUpdate method of tween, and passing positions from the array I've populated in the beginning.
This of course is good if you have very weird paths. If you want very little curves, you could try to do a mathematical equation. Tween classes have an update function, which will be called on each frame. So on each frame you could do some calculations and modify the parameters. For example if you tween x and y properties, you could use the update function to add a random number to those values. Of course this will make very uncontrolled movement, I'm just giving an example.
The best solution I could think of, speaking of complexity/result ratio - to use Greensock's TweenMax (look at the second example) - it has a built in bezier tweening. This means it could move from point A to point B within a bezier curve. I think this will be a good solution for your problem :)
We create some MovieClips and use Motion Tween to animate them.
We create some MovieClips and use Motion Tween to animate them, then render all frames as .png and create MovieClips with all those rendered .pngs.
I guess second way take less time, because you skip tween calculation step. Which way of animation is more proper/fast?
It's of course the first one. Maybe your intention is good but it wouldn't pay off in the long term and it's also micro-optimization and it's considered bad. It doesn't make the code readable and it can slow down your loading time. In general calculation is also faster because you don't need to change the whole screen. So it really depends if the second version uses for example delta packing for the animation.
I'm having an issue with TextFields, whenever I tween the containers that they are inside of, the text will sorta jump and not scale very smoothly. Is there a solution to this problem? I have tried setting cacheAsBitmap, and that doesn't seem to have any effect. Thanks.
Wanted to add that I'm doing this in AIR, and the tweens are not linear, as in, not just an x tween, it is a tween that is affecting both x and y. I have a feeling it may be due to this.
Make sure they are anti-aliased for animation and not for readability. You can find the setting in the textfield properties. If using script, like TweenLite, you may also want to consider rounding the position on update.
Change the anti-alias option to "antialias for animation" instead of "antialias for readablility."
As people in other answers state, you can try to round the values the textfield is set to, to partly (sometimes totally) avoid such "jumps".
If you're using a tween engine, like TweenLite, eaze, anything like that, you can try to look for a method to round the position :
for example by using the RoundPropsPlugin in Tweenlite,
or using the Math.round(value) function in an onUpdate event coming from the tween itself.
Most of the time, good tweening engine will have either (or even both !) of these solutions possible (if not, maybe consider changing engine, TweenLite or eaze are the two bests in my opinion !)
I'm writing a card game in ActionScript 3. Each card is represented by an instance of a class extending movieclip exported from Flash CS4 that contains the card graphics and a flip animation. When I want to flip a card I call gotoAndPlay on this movieclip.
When the frame rate slows down all animations take longer to finish. It seems Flash will by default animate movieclips in a way that makes sure all frames in the clip will be drawn. Therefor, when the program frame rate goes below the frame rate of the clip, the animation will be played at a slower pace.
I would like to have an animation always play at the same speed and as a consequence always be shown on the screen for the same amount of time. If the frame rate is too slow to show all frames, frames are dropped. Is is possible to tell Flash to animate in this way? If not, what is the easiest way to program this behavior myself?
The easiest way would be to use a Timer (or a setInterval) triggering every 1000/fps milliseconds, telling your MovieClip to go to its next frame.
If you need something more accurate, you'll have to check the time spent since the last update (stolen from the first comment of this article from Keith Peters' blog, which explains everything pretty well).
It's been a while since I used Flash but from what I understand it's not possible because Flash uses a frame based animation model.
Silverlight however uses a time based animation model and will just draw as many intermediate frames as the frame-rate allows.
The tween class (fl.transitions.Tween) is perfect for this situation. By setting the last argument of the constructor to TRUE then it bases its animations/triggers off of seconds, and as far as I know it compensates for FPS loss/gain.
You can easily use it like the Timer class by passing a new object (Trigger(new Object(), "x") to the constructor and creating a listener for MOTION_FINISH (TweenEvent.MOTION_FINISH) to trigger your event!
I use Tweens for a LOT of things because they're easy, fast, and supported by everything. And like I said, it should solve your FPS/lag issues since it adjusts to FPS changes in real-time (as far as I know!).