Ejemplo n.º 1
0
        public override object Read(BinaryReader reader, bool xnb)
        {
            AnimatedTexture obj = new AnimatedTexture();

            reader.ReadInt32();
            reader.ReadInt32();
            obj.FrameWidth  = reader.ReadInt32();
            obj.FrameHeight = reader.ReadInt32();
            reader.BaseStream.Seek(reader.ReadInt32(), SeekOrigin.Current);
            List <FrameContent> list = FmbUtil.ReadObject <List <FrameContent> >(reader, xnb);
            Offsets Enumerable.ToArray <Rectangle>(Enumerable.Select <FrameContent, Rectangle>((IEnumerable <FrameContent>)list, (Func <FrameContent, Rectangle>)(x => x.Rectangle)));

            Timing new AnimationTiming(0, list.Count - 1, Enumerable.ToArray <float>(Enumerable.Select <FrameContent, float>((IEnumerable <FrameContent>)list, (Func <FrameContent, float>)(x => (float)x.Duration.TotalSeconds))));
            PotOffset new Vector2((float)(FezMath.NextPowerOfTwo((double)FrameWidth) - FrameWidth), (float)(FezMath.NextPowerOfTwo((double)FrameHeight) - FrameHeight));

            return(obj);
        }
Ejemplo n.º 2
0
        protected override AnimatedTexture Read(ContentReader input, AnimatedTexture existingInstance)
        {
            if (existingInstance == null)
            {
                existingInstance = new AnimatedTexture();
            }
            GraphicsDevice graphicsDevice = ((IGraphicsDeviceService)input.ContentManager.ServiceProvider.GetService(typeof(IGraphicsDeviceService))).GraphicsDevice;
            int            width          = input.ReadInt32();
            int            height         = input.ReadInt32();

            existingInstance.FrameWidth  = input.ReadInt32();
            existingInstance.FrameHeight = input.ReadInt32();
            byte[] data = input.ReadBytes(input.ReadInt32());
            List <FrameContent> list = input.ReadObject <List <FrameContent> >();

            existingInstance.Texture = new Texture2D(graphicsDevice, width, height, false, SurfaceFormat.Color);
            existingInstance.Texture.SetData <byte>(data);
            existingInstance.Offsets   = Enumerable.ToArray <Rectangle>(Enumerable.Select <FrameContent, Rectangle>((IEnumerable <FrameContent>)list, (Func <FrameContent, Rectangle>)(x => x.Rectangle)));
            existingInstance.Timing    = new AnimationTiming(0, list.Count - 1, Enumerable.ToArray <float>(Enumerable.Select <FrameContent, float>((IEnumerable <FrameContent>)list, (Func <FrameContent, float>)(x => (float)x.Duration.TotalSeconds))));
            existingInstance.PotOffset = new Vector2((float)(FezMath.NextPowerOfTwo((double)existingInstance.FrameWidth) - existingInstance.FrameWidth), (float)(FezMath.NextPowerOfTwo((double)existingInstance.FrameHeight) - existingInstance.FrameHeight));
            return(existingInstance);
        }