/// <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]; AnimatedMaterial.SetTexture("_Sprite", CurrentSprite.Sprite); // Update the material tiling: AnimatedMaterial.SetTextureScale("_Sprite", CurrentSprite.TextureScale); }
/// <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>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; BinaryReader br = new BinaryReader(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) { throw new Exception("This reader only supports SPA version 2. The file you have given is version " + version + "."); } FrameRate = br.ReadByte(); // Total frame count: FrameCount = br.ReadUInt32(); // Frame width: FrameWidth = br.ReadUInt16(); // Frame height: FrameHeight = br.ReadUInt16(); // Sprite frame count: int spriteFrames = br.ReadInt32(); 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); } }
/// <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]; AnimatedMaterial.SetTexture("_Sprite",CurrentSprite.Sprite); // Update the material tiling: AnimatedMaterial.SetTextureScale("_Sprite",CurrentSprite.TextureScale); }
//--------------------------------------