views:

722

answers:

3

Hi,

I am working on parallax animation(something like - flordearagua.com) which consist 7-10 layers of quite large(1500x800) bitmaps and MovieClips. To archieve parallax, I wrote code to move all layer at different speed which again depends on some parameters like mouse position and acceleration. All upto this working fine.

I want to make this animation really smoother. I want to achieve minimum 24 FPS with this. currently I am able to achieve only 15-17 FPS with all optimization I've done.

Please note. All component I am using is Library Component. I enabled bitmap catching for some layers but for some I just can't. Enabling bitmap catching for some layers result in jerkiness while performing parallax movement.

Please suggest any optimization.

Thanks.

A: 

Splitting the large images up into smaller images should enable the flash player to perform tests to see if each image is within the viewport area of the stage, and not render it.

So split the images up and add them to a DisplayObjectContainer, so add them to a Sprite. And replace your large image with the group of smaller images. you should see some improvements there.

If this doesn't work you could try and perform the visibility tests manually, making the images that are not in the viewport visible=false.

Brian Heylin
Thanks for reply Brian. But, Don't you think splitting images would require a lot processing in terms of moving them and align them?For visibility, I am already using fastest CopyPixel API to copy only required pixels out of larger Sprites/MovieClips and show them on single Movie Clip.
Bhavesh.Bagadiya
I think breaking up the images will not hinder performance by any great amount, but what it will do is give flash (or a manual routine by you) smaller display objects so it can figure out for itself what is on and off the screen. And I would be careful using the CopyPixels routine, as fast is relative. The question I would have is: fast compared to what? Copying pixels every update is an expensive operation compared to not copying pixels.
Brian Heylin
Hey!You above added comment to catch bitmap. but actually saying I was catching some of the layer but catching all of them make mevement bit jerky.but now as I am using CopyPixel, It is as good as virtual Catching as what I understand!Thanks and your answers are really appreciated..keep posting!
Bhavesh.Bagadiya
A: 

I think this is what you should do -- I can't tell how close to this you already are, though.

  • keep all of the large layers off the display list.
  • on each frame, calculate which section of each layer should be visible.
  • grab bitmapData objects of each layer's currently-visible section.
  • paint them, in order back-to-front, into an empty display object on the display list.

However, it sounds like you're already doing this, or, at least, very close to doing it. Do you have any alpha gradients, complex pngs, or the like that you can simplify? Opaque is always faster than alpha.

JMHNilbog
Hi JMHNilbog!Thanks for reply. I am doing all these my friend. My no layer is on DisplayList exept one on which I am putting only required pixels through CopyPixel() and yes I have many alpha gradients in map. without alpha, how can I properly overlay 7-10 layers on top of each other! so not all but some of them has alpha.
Bhavesh.Bagadiya
I'm considering 'empty space' in a vector clip as different from bitmaps with alpha transparency.
JMHNilbog
+1  A: 

I think you can reach a better performance by keeping everything you can off the display list. Leave a dumb sprite on it only. Calculate the paralax displacement by hand, and compose one bitmap image only, then paint that to the screen with copyPixels, which is very fast.

This gets harder to manage when you need to have fine grained user interaction (clicks or rollovers on certain areas of certain layers). Still so, you can capture mouse events and hook to the same code to determine what and where were clicked.

The catch here, is that you will be, in a way, re-implementing the DisplayObject hierarchy. And that's the crux of it, the native display object is too generic and knows little of the details of your application, so you can optimize it aggressively.

You seem to be well informed of this, but just like any other optimizations, where is the issue really? (profile it!)

The VM these days is pretty good, but the rendering pipeline is awfully slow. You might get a few more FPS from other sources (inlining things, memoization and so forth).

Arthur Debert
Hey Arthur!Thanks.Just to inform, I'm actually doing all these. I have only one sprite in display list where I put only required pixel from other bitmaps.Profiling is really seems good idea but I dont know if any good profiler available for AS3, please note I'm not using Flex. We have a custom build profiler which we used and checked profiling data. but everything seems smooth. no calculation taking much time as Rendering. So still wondering how to achieve my goal... :)
Bhavesh.Bagadiya
Two things to notice, even if this a regular swf app (no-flex), you can still load the main swf into a bootstrapper and profile it with the flex profiler... but...There is no magic hooks to the flex profiler. It uses a less known package, but all calls you need to profile are there (http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/sampler/package.html). it's well worth profiling in your case. You've already taken the obvious steps to ensure performance, so it's a good idea to start problem less obvious solutions.Cheers
Arthur Debert