/// <summary>Creates a map entry, loading the coords from the given reader.</summary> public SPAMapEntry(SPASprite sprite, SPAReader reader) { // Get the sprite as an atlas: TextureAtlas atlas = sprite.Atlas; // ID: ID = (int)reader.ReadCompressed(); // Coords are.. int x = (int)reader.ReadCompressedSigned() + reader.PreviousX; int y = (int)reader.ReadCompressedSigned() + reader.PreviousY; // Update previous: reader.PreviousX = x; reader.PreviousY = y; // Read the dimensions: int width = (int)reader.ReadCompressed(); int height = (int)reader.ReadCompressed(); // Create the atlas location now: Location = new AtlasLocation(atlas, x, y, width, height); // Prevent this location from getting recycled: Location.PreventDeallocation(); }
/// <summary>Creates a character map entry, loading the coords from the given reader.</summary> public SPACharacter(SPASprite sprite, SPAReader reader) : base(sprite, reader) { // Note that the rest of the map entry has been loaded. // Now just need the xoffset etc. // So, offsets are: XOffset = (int)reader.ReadCompressedSigned(); YOffset = (int)reader.ReadCompressedSigned(); // Advance is: Advance = (int)reader.ReadCompressedSigned(); }
/// <summary>Creates space for the given number of sprites which hold the given total number of frames.</summary> /// <param name="spriteCount">The number of sprites.</param> /// <param name="frameCount">The total number of frames held by the sprites.</param> public void CreateSprites(int spriteCount, uint frameCount) { // Apply the frame count: FrameCount = frameCount; // Setup the sprite array: Sprites = new SPASprite[spriteCount]; // Create each one: for (int i = 0; i < spriteCount; i++) { Sprites[i] = new SPASprite(this, i); } }
/// <summary>Sets the sprite with the given ID as the active one.</summary> /// <param name="index">The ID of the sprite.</param> private void SetSprite(int index) { CurrentSprite = Animation.Sprites[index]; if (CurrentSprite.Delay != 0f) { // Get the delay from the sprite: FrameDelay = CurrentSprite.Delay; } if (AnimatedMaterial == null) { // Nobody is displaying it! return; } AnimatedMaterial.SetTexture("_MainTex", CurrentSprite.Sprite); // Update the material tiling: AnimatedMaterial.SetTextureScale("_MainTex", CurrentSprite.TextureScale); }
/// <summary>Creates a new SPA animation with the given name from the given binary data.</summary> /// <param name="name">The name of the animation. Used for caching purposes so the binary doesn't /// have to be reloaded if the animation is displayed multiple times.</param> /// <param name="binaryData">The raw binary data of the spa file.</param> public SPA(string name, byte[] binaryData) { Instances[name] = this; SPAReader br = new SPAReader(new MemoryStream(binaryData)); if (br.ReadChar() != 'S' || br.ReadChar() != 'P' || br.ReadChar() != 'A') { throw new Exception("This is not an SPA file."); } byte version = br.ReadByte(); if (version != 2 && version != 3) { throw new Exception("This reader supports SPA versions 2 and 3. The file you have given is version " + version + "."); } int spriteFrames; if (version == 2) { // FR: FrameRate = br.ReadByte(); // Total frame count: FrameCount = br.ReadUInt32(); // Frame width: FrameWidth = br.ReadUInt16(); // Frame height: FrameHeight = br.ReadUInt16(); // Sprite frame count: spriteFrames = br.ReadInt32(); } else { // FR: FrameRate = (int)br.ReadCompressed(); // Total frame count: FrameCount = (uint)br.ReadCompressed(); // Frame width: FrameWidth = br.ReadUInt16(); // Frame height: FrameHeight = br.ReadUInt16(); // Sprite frame count: spriteFrames = (int)br.ReadCompressed(); } Sprites = new SPASprite[spriteFrames]; // Next, read each of the sprite frames: for (int i = 0; i < spriteFrames; i++) { Sprites[i] = new SPASprite(this, br, i); } }