30

What I'm looking is a flash alternative for mobile phones using html5.

I was looking into SVG and it seems the only way to get hardware acceleration is to use CSS transforms on it. But CSS transforms aren't enough, I want to animate the actual nodes that make up a vector (ie, points on a path) so I could get more sophisticated character animation. To do this I was looking at some gui based editors.

I checked what adobe has been up to and they seem to have killed Edge Animate and rebranded Flash as "Animate CC" for 2016.

http://blogs.adobe.com/creativecloud/update-about-edge-tools-and-services/ https://blogs.adobe.com/flashpro/welcome-adobe-animate-cc-a-new-era-for-flash-professional/

But reading up on "Animate CC" I see that it exports vector animations to either Canvas or WebGL. Which I think is due to them not getting hardware acceleration with native SVG via SMIL or using javascript. https://css-tricks.com/guide-svg-animations-smil/

Another one is http://www.animatron.com which converts everything to canvas as well.

So my question is, in order to do keyframe animations on nodes within a vector path, a vector needs to be converted to either WebGL or Canvas for it to be hardware accelerated on mobile?

p.s I prefer using SVG as it's loaded in the DOM and I can manipulate things with jquery. This is for a mobile game that uses vectors (svg) as its base but I'd like to incorporate animations too - beyond the basic css transforms. I wish there was a way to have a .svg file that not only contains the vector information but also the animation info. so I could load this .svg file. and then in javascript go: character1.play('animation1') or something. If SMIL worked fast I'm sure editors like adobe would make it as simple as that.

EDIT: I just read that Chrome 45 killed SMIL in favor of "web animations" and css. https://developer.mozilla.org/en-US/docs/Web/SVG/SVG_animation_with_SMIL And as Kaiido mentioned in the comments IE never supported smil so maybe that's why adobe never exported to it (?). http://caniuse.com/#feat=svg-smil also I never saw any examples online that show hardware accelerated path animation with smil, if any of you guys find a link pls let me know.

EDIT #2: I'm thinking of giving up my wishful thinking and instead looking at vector to canvas exporters like animatron.com. However, it doesn't seem like canvas is even hardware accelerated or fast like css3 transforms. I loaded some animations from animatron in my old iPhone 4s/iOS 8 and it's jittery and slow for example: https://www.animatron.com/project/1953f3526e5b2ec4eef429c8 whereas css3 transform animations always run very smooth...

I still haven't tested vector to webgl.. but I think that's why adobe eventually chose to use it for their vector animations since canvas is slow and svg is limited.

EDIT #3: sure enough it seems like webgl is the way to go (unless someone finds a way to do this with native svg) http://www.yeahbutisitflash.com/?p=7231 .. this works fast in my iphone 4s/ios8.. I currently think this is the only way to do what I want: hardware accelerated vector based animation (however the graphics don't look as crisp as I'd want them.. webgl kinda messed with that I think). but this is why I think Edge Animate got killed cause they were trying to create a tool that took advantage of css3 transforms, but ppl want to animate vector nodes so they went back to Flash and rebranded it. (another note: the above webgl anim doesn't work so well on my galaxy S4/kitkat android phone.. so this is mainly for newer devices/OSs)

EDIT #4: come to think of it. it'd be a pain to have multiple webgl contexts running in my program. so if I had 10 animated characters I'd have to have 10 webgl contexts which would be intense for a mobile device.. unless I chose to do the whole game in flash, and then I'd have one big webgl context after I export it. but I prefer to work in the dom. oh well css3 transforms for the meantime.. :/

EDIT #5 - Dec 2016: I'm now using svg/javascript with snap.svg. modern phones seem fast enough.

Other Useful Links I Found:

http://www.crmarsh.com/svg-performance/

Shai UI
  • 45,518
  • 63
  • 187
  • 278
  • **ie, we cannot use SVG right?** http://caniuse.com/#feat=svg .. why not? – ymz Jan 19 '16 at 00:15
  • 1
    I'm not sure I understand. What makes you think animating the nodes would be hardware accelerated or not using either SVG or Canvas/WebGL? I would think the actual animation of the points would need to be done on the CPU, and then it's up to the browser to decide to draw it on either the CPU or GPU. – Alexander O'Mara Jan 19 '16 at 01:22
  • 1
    well the browser doesn't do that. if you try animating svg points via javascript or smil it's plain slow. for example, running the animations from http://raphaeljs.com/animation.html on your mobile phone you'll see what i mean. that's why I think adobe chose to do it with webgl. see http://airtightinteractive.com/projects/winter-rush/ on your phone for webgl hardware acceleration. I'm almost certain but I wanted to make sure others before as it has alot of ramifications in code. – Shai UI Jan 19 '16 at 01:32
  • 1
    IMM the only way to do "morph animation" (if this is what you are after), hardware accelerated would be using SMIL since it's the only language that does support this type of animation natively. CSS can't animate `d` attribute, hence you can't do morphing through CSS. WebGL and context2d doesn't have such methods either and you will have to make all the points calculations with JS (on the CPU). What is hardware accelerated is the pixels processing (composite operations, shaders etc.). – Kaiido Jan 19 '16 at 02:07
  • 1
    Ps : the raphael example you do provide is of no use, since raphael is not using SMIL, it's a js library that does all the calculations on CPU, through js... A real test would be one that uses `` element, since, according to [this article which could be a good reading for you](https://css-tricks.com/weighing-svg-animation-techniques-benchmarks/) this element's transformations are hardware accelerated. – Kaiido Jan 19 '16 at 03:11
  • Thanks for that article. I'll check it out. I was just reading that smil is getting deprecated tho. technology moves fast. sigh. also if was good why didn't adobe use it.. anyway, still researching thanks. – Shai UI Jan 19 '16 at 03:15
  • SMIL is not deprecated, yet. Only Chrome did stop their support because ["it's too hard"](https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/5o0yiO440LM[101-125]) for them. Adobe didn't used it because IE never supported SMIL. As I said earlier, no other alternative do support morphing natively (nor does web animations). There are js polyfills for browsers that don't support SMIL, but then it won't have hardware acceleration of course. But your question starts to become a bit too broad doesn't it? – Kaiido Jan 19 '16 at 03:22
  • I'm not sure about the use of the term "morphing". I just mean animate nodes on a vector path. Flash has been doing that for the last 20 years. I'm just looking for a fast html5 mobile solution that doesn't necessarily involve pixel based canvas or webgl which are too low level for what I want. – Shai UI Jan 19 '16 at 03:25
  • You can try to have technology fit your needs or you change your needs to fit the technology. The advantage we have now over 10 years ago is we have huge amounts of ram and fast data speeds. At 60Fps you can have all the tweening done during production (yes lots of data, very compressible data) and then just play each frame one after the other, nobody will ever notice the difference. Unless you are tweening 2 or more targets at the same time this is an effective solution to lack native processing speed. – Blindman67 Jan 19 '16 at 05:16
  • `typeof Animate CC === 'vomit'` You should check out GSAP https://greensock.com/gsap – CervEd Oct 17 '16 at 00:33

5 Answers5

2

Canvas is (as far as i know) software accelerated. So it's rendered by the processor (CPU). The processor (cause of them pixels) ain't that good at graphical stuff but for simple things it would be enough. And it runs everywhere, where there is a processor.

If you want to have better performance on hardware accelerated devices which most modern smartphones are, you need webgl. But you can export your stuff in webgl from adobe CC. Older smartphones are not very optimized on hardware acceleration so please check with your target group what devices they have and try to run your app on one of the slowest devices.

I would not use SVG. SVG is even worse than DOM. You can be faster manipulating HTML in javascript than SVG. I don't know why but it is damn slow. SVG is just an alternative if you want to have scalable graphics or charts and that's what it is made for. To animate in SVG is a pain. Don't do it. It is not optimized for animation.

CSS-Transform is a prototype-like and will not help you with keyframe animation. But it has potential to have an eye on it.

Does this help you?

Kilian Hertel
  • 147
  • 13
0

I think its a difficult question to answer as there's so many issues with different browsers. Some don't support SMIL transforms well (or being deprecated, but as mentioned there are fills for it), some don't support CSS3 transforms on SVG elements at all, so most of the 'solutions' out there, have some issue that may need to be compromised on. I think one browser doesn't support d attribute morph properly, but I can't recall which (so test this early on with required browsers if you do go down this route).

Canvas does typically seem to perform better on mobile for most animation I've seen or played with, certainly as the number of objects increases on page.

Other alternatives to webGL that was mentioned..

One option that kinda springs to mind is fabric.js, which is a canvas approach to SVG. It will take the same commands, elements as SVG, but display it on an HTML5 canvas. Turn off drag/freetransform within it (as I think its slowed down a bit with this if it needs extra checks), and I think it will be a bit faster, but its a while since I've played. This could be an interesting approach if you don't need specific DOM element access, but would be fine if you are ok with a similar object based setup.

If you insist on using SVG, then I would look at integrating it with another library (or even 2). Snap or SVG.js are both decent, but can be a bit slow. However, I would experiment with using Velocity.js or React.js with that svg library, as they have some methods that can squeeze out a bit more performance. Also GSAP may be worth a look.

Ian
  • 12,839
  • 3
  • 46
  • 67
  • thanks for your input. What I'm really trying to do is use a program to edit vector and keyframe animations (as it'd be a chore to do this in code) and then load this animation in code. so fabric or snap or svg.js don't really help for this purpose. I noticed that all the editors today export to either canvas or webgl. unless browsers implement gpu rendering for svgs then I guess we'll be seeing webgl in the foreseeable future. (or plain canvas.. but canvas is slower I find) – Shai UI Jan 19 '16 at 21:09
  • Problem with keyframe animations on svg is that many don't work in IE for example, so if you care at all about IE, you can't do it. WebGL isn't all that well supported on mobile (although is improving). So I think whichever way you look at it, there are potential issues, and I think you need to focus on where your target is, and if its viable. There are clever things folk can do, but really making sure it works on your target setups feels key. – Ian Jan 19 '16 at 21:43
  • The example I gave earlier with http://www.yeahbutisitflash.com/?p=7231 works fine on IE. as far as svg based keyframe animations. nobody ever attempted doing that - either with js or smil. well atleast I couldn't find any examples online.. and it wouldn't be fast on mobile anyway. – Shai UI Jan 19 '16 at 21:56
  • err maybe it would be fast on mobile if they used but if chrome's deprecating it.. it's a bit meh. plus never saw any examples of this in conjunction with a vector based editor like flash. – Shai UI Jan 19 '16 at 22:32
  • The example you mention is WebGL which can work on IE, but not on some other mobile browsers. Its SVG + CSS3 transforms that have issues on IE. AnimateTransform has issues on Firefox iirc. Ie basically there are issues with pretty much all of them, apart from possibly canvas. The other method would be to optimise SVG via other methods as mentioned, or even possibly combine canvas and svg or similar. You may need to get creative. – Ian Jan 20 '16 at 09:33
  • oh really, svg+css3 is messed up on edge too? – Shai UI Jan 20 '16 at 16:51
0

There is no general answer to this, it depends on the browser implementation and your hardware, but ... for the long term solution I would bet on WebGL because it uses the GPU and will ultimately dominate.

WebGL is not well supported right now (2016), and it potentially comes with security issues. Also see: https://css-tricks.com/rendering-svg-paths-in-webgl/

Canvas is better at working on raw 2d pixel buffers (+ alpha channel) and is slow for higher resolution+animation. You could use some dual lib like Pixi though.

Community
  • 1
  • 1
Christophe Roussy
  • 13,732
  • 2
  • 75
  • 75
0

If you don't mind the k-weight increasing a bit and are comfortable using flash, the easiest and the fastest solution would be to use Animate CC (It's exactly Flash, without the symbol filters and gives canvas output instead of swf).

DKaikster
  • 46
  • 5
0

This library/plugin might be exactly what you are looking for: Greensock SVG Morph Plugin. It seems to perform pretty well on mobile, not sure how well it performs on devices mentioned by you.

It's also not GPU accelerated but Greensock Animation Platform seems to perform extremely well even on mobile devices.

meinaart
  • 87
  • 4