Exemple #1
0
        public override object Read(BinaryReader reader, bool xnb)
        {
            AnimatedTexture obj = new AnimatedTexture();

            int width  = reader.ReadInt32();
            int height = reader.ReadInt32();

            obj.FrameWidth  = reader.ReadInt32();
            obj.FrameHeight = reader.ReadInt32();

            int       dataSize = reader.ReadInt32();
            Texture2D texture  = Texture2DHandler.GenTexture(width, height, SurfaceFormat.Color, 1);

#if XNA
            //For XNA, we simply pass the data for the only level.
            texture.SetData(0, null, reader.ReadBytes(dataSize), 0, dataSize);
#elif UNITY
            //Oh, Unity, wh~ oh, just one level. Continue on.
            texture.LoadRawTextureData(Texture2DHandler.Remap(reader.ReadBytes(dataSize), SurfaceFormat.Color));

            //updateMipmaps is true by default; makeNoLongerReadable should be false.
            texture.Apply(false, FmbUtil.Setup.TexturesWriteOnly);
#endif

            obj.Texture = texture;

            FrameContent[] list = FmbUtil.ReadObject <List <FrameContent> >(reader, xnb).ToArray();
            obj.Offsets   = FmbHelper.Select <FrameContent, Rectangle>(list, delegate(FrameContent x) { return(x.Rectangle); });
            obj.Timing    = new AnimationTiming(0, list.Length - 1, FmbHelper.Select <FrameContent, float>(list, delegate(FrameContent x) { return((float)x.Duration.TotalSeconds); }));
            obj.PotOffset = new Vector2((float)(FmbHelper.NextPowerOfTwo(obj.FrameWidth) - obj.FrameWidth), (float)(FmbHelper.NextPowerOfTwo(obj.FrameHeight) - obj.FrameHeight));

            return(obj);
        }
Exemple #2
0
 public AnimationTiming(int startFrame, int endFrame, bool loop, float[] frameTimings)
 {
     Loop              = loop;
     FrameTimings      = FmbHelper.Select <float>(frameTimings, delegate(float x) { return(x != 0f ? x : 0.1f); });
     stepPerFrame      = 1f / (float)frameTimings.Length;
     InitialFirstFrame = StartFrame = startFrame;
     InitialEndFrame   = EndFrame = endFrame;
 }