A very easy manner of making animation using sprite image in Corona lab. A sprite is largely a ground of pictures composed into one huge image, where every item represents a inclose timeline. By enjoying these frame one by one in no time, we have a tendency to produce an illusion of animation. Well, that is the same Persistence of Vision the factor the primary Projectors accustomed to work on…


So, now, we have a sprite image ready below:

sprite copy

The filename image is sprite.jpg, with size in 648 (width) x 214 (height) pixel. There are total four frames, simply an easy animation. every frame size is 162 (width) x 214 (height) pixel. Currently the coding part. In corona, we have a tendency to initial ought to initialize the image sheet data:

We take in five parameters once making sheetData variables:

  1. width: width of the single frame 648/4 = 162 pixel
  2. height: always 214 pixel as our sprite image is a horizontally long image. There are additional difficult cases wherever your sprite can be over one row.
  3. Num Frames: solely four here as you’ll be able to see
  4. Sheet Content Width: your sheet image size in width, is 648 pixel
  5. Sheet Content Height: same as above, however tall, is 214 pixel

Once you get these worth set properly, you produce the imageSheet variable by passing within the image file path and name, then this sheetData too as parameters. Next, you need to create another variable referred to as sequenceData. This may tell corona the way to play your sprite. Our animation here is incredibly simple, simply keep looping it from first frame to last frame.

Then, we produce the loadingSprite object using imageSheet and sequenceData as parameters.

For more advanced and complete tutorial, please refer to Coronalab Tutorial here.