Best way to do a looping move effect in flex? - apache-flex

I want to display an animated arrow that goes back and forth (using flex 4). I'm using the following move effect :
<s:Move id="animateArrow" target="{arrow}" duration="750" repeatCount="0" repeatBehavior="reverse" yFrom="{arrow.y}" yTo="{arrow.y - 25}"/>
When needed, I then play the effect:
animateArrow.end();
animateArrow.play();
The animation works as intended but it seems to be a huge resource hog while playing. Any logic that happens while playing the animateArrow effect takes a very long time to load. Is there a better way of doing this?

Any effect will take resources. If it's taking more cpu than anticipated, you might want to look at the object you're moving, it's container, and the code it might affect.
Personally, I wouldn't use Adobe's animation library as they aren't very optimized. I would look at TweenMax instead.

Related

Mysterious animation lag on second monitor

So I'm working on this app in electron, and I noticed when I move the app over to my second monitor it seems to lag. Curious what might be causing this- I opened up the dev console, and sure enough- my animations drop from a very comfortable 100-150 fps, to a consistent sub 50 fps. The animation is a height transition, which is poorly handled by the browser, but even this doesn't explain the massive performance drop I see by simply dragging the window over to my second monitor.
I'm considering rethinking the way I handle the animation, to mimic the current look of it using only transforms, but it would be nice to know what's causing the stuttering and lag, since the lag doesn't appear to be specific to my height transition. After digging around for a bit in search of an answer, I'm no closer to anything that might be called a solution. I'm not posting any code with this because none of the animations are handled with JS. It just plain and simple CSS- nothing crazy about it.
To me this seems like it more of an underlying issue with electron itself, or perhaps something strange the OS does.

Practical differences between SVG and Canvas within a ggvis & Shiny Context

I have already read
What is the difference between SVG and HTML5 Canvas?
&&
https://en.wikipedia.org/wiki/Canvas_element#Canvas_versus_Scalable_Vector_Graphics_.28SVG.29
So i am aware of the basic differences, but i was wondering if anyone had encountered any practical difference between the two within the context of ggvis and shiny apart from SVG inability to deal with NA's in the data
The short answer:
SVG would be easier for you, since selection and moving it around is already built in. SVG objects are DOM objects, so they have "click" handlers, etc.
DIVs are okay but clunky and have awful performance loading at large numbers.
Canvas has the best performance hands-down, but you have to implement all concepts of managed state (object selection, etc) yourself, or use a library.
The long answer:
HTML5 Canvas is simply a drawing surface for a bit-map. You set up to draw (Say with a color and line thickness), draw that thing, and then the Canvas has no knowledge of that thing: It doesn't know where it is or what it is that you've just drawn, it's just pixels. If you want to draw rectangles and have them move around or be selectable then you have to code all of that from scratch, including the code to remember that you drew them.
SVG on the other hand must maintain references to each object that it renders. Every SVG/VML element you create is a real element in the DOM. By default this allows you to keep much better track of the elements you create and makes dealing with things like mouse events easier by default, but it slows down significantly when there are a large number of objects
Those SVG DOM references mean that some of the footwork of dealing with the things you draw is done for you. And SVG is faster when rendering really large objects, but slower when rendering many objects.
A game would probably be faster in Canvas. A huge map program would probably be faster in SVG. If you do want to use Canvas, I have some tutorials on getting movable objects up and running here.
Canvas would be better for faster things and heavy bitmap manipulation (like animation), but will take more code if you want lots of interactivity.
I've run a bunch of numbers on HTML DIV-made drawing versus Canvas-made drawing. I could make a huge post about the benefits of each, but I will give some of the relevant results of my tests to consider for your specific application:
I made Canvas and HTML DIV test pages, both had movable "nodes." Canvas nodes were objects I created and kept track of in Javascript. HTML nodes were movable Divs.
I added 100,000 nodes to each of my two tests. They performed quite differently:
The HTML test tab took forever to load (timed at slightly under 5 minutes, chrome asked to kill the page the first time). Chrome's task manager says that tab is taking up 168MB. It takes up 12-13% CPU time when I am looking at it, 0% when I am not looking.
The Canvas tab loaded in one second and takes up 30MB. It also takes up 13% of CPU time all of the time, regardless of whether or not one is looking at it. (2013 edit: They've mostly fixed that)
Dragging on the HTML page is smoother, which is expected by the design, since the current setup is to redraw EVERYTHING every 30 milliseconds in the Canvas test. There are plenty of optimizations to be had for Canvas for this. (canvas invalidation being the easiest, also clipping regions, selective redrawing, etc.. just depends on how much you feel like implementing)
There is no doubt you could get Canvas to be faster at object manipulation as the divs in that simple test, and of course far faster in the load time. Drawing/loading is faster in Canvas and has far more room for optimizations, too (ie, excluding things that are off-screen is very easy).
Conclusion:
SVG is probably better for applications and apps with few items (less than 1000? Depends really)
Canvas is better for thousands of objects and careful manipulation, but a lot more code (or a library) is needed to get it off the ground.
HTML Divs are clunky and do not scale, making a circle is only possible with rounded corners, making complex shapes is possible but involves hundreds of tiny tiny pixel-wide divs. Madness ensues.
I have past content from the following link.
Please see this link for more details
HTML5 Canvas vs. SVG vs. div

How can I make this effect by using css3?

This is an amazing effect like PPT. Link is here :
http://udc.weibo.com/builder2011/data.html
I know single part was made by css3-animation effects but I don't know
1.how to play all these effects in a timeline?
2.how to make position change and local to whole effect?
Where can I find a tutorial like this?
Thanks cordially.
You could actually make the whole thing out of CSS3.
Keyframes is how you'd be able to time the different functions: http://www.leemunroe.com/css3-animations/
You would need something like an entire CSS3 powered page page, and then just place a window over that with overflow hidden. Use keyframe to move the page around but the window will only show a portion of it.
Just realized, that actually happens to be exactly what they did.

Is Alpha affecting performance on Flex somehow?

I am planing to setup all of controls ( more than 100 visible ) on a Flex application to alpha below 1, which will make them a bit transparent, but i am wondering if this will affect the performance of the application. So :
I would like to know if alpha actually affecting performance on Flex applications ?
To add to #Constantiner's answer, every filter and effect (including alpha) will affect performance. This is the case in any framework you work with... not just Flex. If you think about it, it makes sense...
You see, without any effects or filters, what gets displayed is straight forward... it is just a pixel. If the pixel is in front of every other pixel on the Z axis, it gets displayed. If not, it doesn't get rendered. No math. Very easy for the computer to manage.
In your case, you are changing the alpha. Now, for every pixel in front with an alpha value less than 1, you ALSO have to render to content behind it. Not only do you need to render the content behind it, you need to blend the pixels in order to get the transparent effect.
Of course, the framework and GPU take care of this work for you... but it comes at a cost. I am not suggesting that you don't use alphas. Just know that every time you add an effect or filter (drop shadows, glows, alpha blends, blurs, etc), the system has to do a lot more math for you. Your frame rate is directly affected by this... but it also produces a much better experience for your user.
Use that knowledge to make an educated decision. Does the effect/filter add value? Does the alpha move around a lot like in a scrolling list box (causing re-rendering to happen more often)? Will this extra overhead be OK?
EDIT:
Take a look at this presentation from 360Flex about optimizing Flex performance. I think it is very useful: http://zaa.tv/2011/06/360flex-denver-2011-flex-performance-tips-and-tricks/
Yes, it potentially affects performance. So use it wisely.
I mean if you're using controls with constant background there is no problems with it. But if you have a lot of objects which moves or added/removed to stage often you can have some performance issues.

How to Queue or Pipeline Many Flex Animations?

I have a Flex application where some interactions cause many objects to require visual updates all at once. These updates translate into state changes for many MXML based components which have state based transitions. The transitions look great when just a handful of the components animate at the same time... but when all of them animate at once... the Flash Player just can't keep up.
Any ideas on how to create something of an animation pipeline so that everything can have a chance to keep up? Or maybe some other solution?
Did you try working with suspendBackgroundProcessing property of Effect or disableLayout property of Animate class descendants? You can define them on MXML animation definition nodes.
Personally, I try to stay away from the Adobe effects library as they're slow and not all that good. If you want animation 'groupings', consecutive animations, or even animation timelines, I would suggest you use TweenMax.

Resources