UV Scrolling Material for Alternativa3D 

Originally created by David Jones i modified his class in order to add this features:

  1. currentFrame set/get property. Number of frame from the Texture Atlas used.
  2. Allows to specify which padding you used in the texture atlas (the empty pixels surrounding each frame/sprite) This  is usefull because if all the Sprites are next to each other you will see the borders acting weird. Leave a padding of 2 pixels to have clean borders. (remember the padding is the same you use when creating the TextureAtlas)
  3. Make it work with a bidimensional texture atlas. When you export a MovieClip from Flash as a texture atlas, it will wrap the sprites if they go outside the width of the image. The class can guess how many sprites per row because it assumes all sprites have the same size. This class is meant to be used to animate, so all sprites must have the same size.
  4. Allows to scroll the opacityMap aswell. You have 2 choises: 1) scroll the same way as the diffuse map. 2) do not scroll, use the entire map.
  5. Allows to set a custom “totalFrames”, because flash sometimes creates a big image to make it a power of two and not every inch of the image is used by sprites. So you can manually set how many frames the atlas has. Else, it will be calculated based on the image dimensions and how many sprites can hold the width and height (taking into account the padding also)

Download the class and example files.

LIVE DEMO (click image below, no preloader 172kb):

You will see in the demo, in the left, the UVScrollMaterial is set to not scroll the opacityMap. In the right, the opacityMap is treated also as a textureAtlas in the same way as the Diffusemap. Both in sync.