Object-Spriteset

From Spheriki

Jump to: navigation, search

Encapsulates an entire spriteset, normally used to represent a person on a map. It contains direction animations and a base, giving a person both their appearance and their footprint size.


Contents

Initializers


Methods


Members

  • base Sphere SpritesetBase object. The footprint size and position.
  • directions Array of Sphere SpritesetDirection objects. The different direction animations of the spriteset.
  • filename String. Filename of the source of the spriteset.
  • images Array of Sphere Image objects. SpritesetFrames inside each of the elements of directions[] array refer to these images.


Examples

A step-by-step method to get the image associated with a frame.

Get your spriteset.

var ss = LoadSpriteset("bob.rss");

Find the direction you need by searching through the array.

var dir_name = "south";
var index = -1;
for (var d = 0; d < ss.directions.length && index === -1; ++d)
{
  if (ss.directions[d].name === dir_name)
    index = d;
}

If we found it, we can pick our frame, e.g. the fifth frame (index 4).

if (index !== -1)
{
  var frame = ss.directions[index].frames[4];

And get the index of the image.

  var index = frame.index;

Finally, we can grab our image by going back to the spriteset itself.

  var image = ss.images[index];
  // Do stuff with image
}

Flikky has some nice examples over at his site.

Notes

Spritesets represent the physical being of a person entity on a map. Both size and appearance are determined by a spriteset.

It can be a bit complex, but this is the breakdown:

  • Spritesets have images, directions and also a base.
  • A base is just an invisible rectangle which determines what a person will bump into at what places, if assigned this spriteset.
  • Directions are just named animations, filled with frames.
  • Frames are nothing more than a reference to the images array, and a delay.

If you want to get the images, you'll need to use the images array. If you want to find out which image a frame refers to, you'll need to choose the direction, then the frame, and get the image index from there.


See also

Personal tools