protected override Asset Read(BinaryReader input)
        {
            String name = input.ReadString();
            Animation animation = new Animation(name);

            int framesCount = input.ReadInt32();

            AnimationFrame[] frames = new AnimationFrame[framesCount];
            for (int frameIndex = 0; frameIndex < frames.Length; ++frameIndex)
            {
                frames[frameIndex].x = input.ReadInt32();
                frames[frameIndex].y = input.ReadInt32();
                frames[frameIndex].ox = input.ReadInt32();
                frames[frameIndex].oy = input.ReadInt32();
                frames[frameIndex].w = input.ReadInt32();
                frames[frameIndex].h = input.ReadInt32();
                frames[frameIndex].duration = input.ReadInt32() * 0.001f;
            }

            animation.frames = frames;

            int textureSize = input.ReadInt32();
            byte[] data = input.ReadBytes(textureSize);

            using (MemoryStream stream = new MemoryStream(data))
            {
                Texture2D texture = Texture2D.FromStream(Runtime.graphicsDevice, stream);
                animation.texture = new TextureImage(texture);
            }

            return animation;
        }
        public FrameState(AnimationFrame frame)
        {
            _scale = frame.Scale;
            _rotate = frame.Rotation;
            _translate = frame.Translation;

            CalcTransforms();
        }
Esempio n. 3
0
        public ShieldEffect()
        {
            texture = Game1.contentManager.Load<Texture2D>("effects/explosions");   //65x65 - 512:260
            af = new AnimationFrame(8, 4, 1, 64, 64);
            offX = 8;
            offY = 12;
            origin = new Vector2(32, 32);

            color = new Color(10, 0, 255, 0);
            alphaAmount = 255/(8 * 4);
        }
    public void AddFrame(Texture2D image, AudioClip audio)
    {
        if (image == null && audio == null)
        {
            AddFrame();
        }

        AnimationFrame toAdd = new AnimationFrame(lastFrame, image, audio);
        lastFrame++;
        keyframes.Add(lastFrame, toAdd);
    }
Esempio n. 5
0
    public bool AddFrame(string animationName, int x, int y, int width, int height, int offsetX = 0, int offsetY = 0)
    {
        if(animations.ContainsKey(animationName))
        {
            AnimationFrame frame = new AnimationFrame(x, y, width, height, offsetX, offsetY);
            animations[animationName].Add(frame);

            return true;
        }

        else
            return false;
    }
        public AnimationFrameSaveContent(AnimationFrame template)
        {
            FrameLength = template.FrameLength;
            TextureName = template.TextureName;
            FlipVertical = template.FlipVertical;
            FlipHorizontal = template.FlipHorizontal;

            LeftCoordinate = template.LeftCoordinate;
            RightCoordinate = template.RightCoordinate;
            TopCoordinate = template.TopCoordinate;
            BottomCoordinate = template.BottomCoordinate;

            RelativeX = template.RelativeX;
            RelativeY = template.RelativeY;
        }
Esempio n. 7
0
        public ExplosionEffect(Vector2 pos)
        {
            texture = Game1.contentManager.Load<Texture2D>("effects/explosions");   //65x65 - 512:260
            af = new AnimationFrame(8, 5, 1, 64, 64);
            offX = 0;
            offY = 12;
            origin = new Vector2(32, 32);
            this.position = pos;

            color = new Color(255, 255, 255, 255);
            alphaAmount = 255 / (8 * 4);

            timer = 0;
            list.Add(this);
        }
Esempio n. 8
0
        public override AnimationFrame Calculate(float dt, AnimationFrame cur, AnimationFrame next)
        {
            AnimationFrame result = new AnimationFrame();

            BlendColors(cur.GetDomeLEDColor, next.GetDomeLEDColor, result.SetDomeLEDColor, Dome.NUM_RIBS, Dome.LEDS_PER_RIB);
            BlendColors(cur.GetPendantLEDColor, next.GetPendantLEDColor, result.SetPendantLEDColor, Dome.NUM_PENDANTS_MAX, Dome.LEDS_PER_PENDANT_MAX);
            BlendColors(cur.GetSatelliteLEDColor, next.GetSatelliteLEDColor, result.SetSatelliteLEDColor, Dome.NUM_SATELLITES, Dome.LEDS_PER_SATELLITE);

            /*
            for (int rib = 0; rib < Dome.NUM_RIBS; ++rib)
            {
                for (int row = 0; row < Dome.LEDS_PER_RIB; ++row)
                {
                    Color b = cur.GetDomeLEDColor(rib, row);
                    Color a = next.GetDomeLEDColor(rib, row);

                    Color newColor = new Color();
                    newColor.A = (byte)(a.A * m_CurBlendValue + b.A * m_Reciprocal);
                    newColor.R = (byte)(a.R * m_CurBlendValue + b.R * m_Reciprocal);
                    newColor.G = (byte)(a.G * m_CurBlendValue + b.G * m_Reciprocal);
                    newColor.B = (byte)(a.B * m_CurBlendValue + b.B * m_Reciprocal);

                    result.SetDomeLEDColor(rib, row, newColor);
                }
            }

            for (int pendant = 0; pendant < Dome.NUM_PENDANTS_MAX; ++pendant)
            {
                for (int led = 0; led < Dome.LEDS_PER_PENDANT_MAX; ++led)
                {
                    Color b = cur.GetPendantLEDColor(pendant, led);
                    Color a = next.GetPendantLEDColor(pendant, led);

                    Color newColor = new Color();
                    newColor.A = (byte)(a.A * m_CurBlendValue + b.A * m_Reciprocal);
                    newColor.R = (byte)(a.R * m_CurBlendValue + b.R * m_Reciprocal);
                    newColor.G = (byte)(a.G * m_CurBlendValue + b.G * m_Reciprocal);
                    newColor.B = (byte)(a.B * m_CurBlendValue + b.B * m_Reciprocal);

                    result.SetPendantLEDColor(pendant, led, newColor);
                }
            }
            */

            base.Calculate(dt, cur, next);
            return result;
        }
Esempio n. 9
0
        public override void GenerateNewFrame(float dt)
        {
            AnimationFrame output = new AnimationFrame(); // get a clear frame

            for (int rib = 0; rib < Dome.NUM_RIBS; ++rib)
            {
                for (int row = 0; row < Dome.LEDS_PER_RIB; ++row)
                {
                    float ribvalue = (float)rib + 1.0f;
                    float rowvalue = (float)row + 1.0f;
                    float brightness = (float)(Math.Sin(m_Delta * ribvalue * rowvalue));
                    brightness += 1.0f;
                    brightness /= 2.0f;

                    Color newColor = m_Color * brightness;
                    output.SetDomeLEDColor(rib, row, newColor);
                }
            }

            m_Delta += 2.5f * dt;
            m_CurrentFrame = output;
        }
Esempio n. 10
0
        public override AnimationFrame Calculate(float dt, AnimationFrame cur, AnimationFrame next)
        {
            AnimationFrame result = new AnimationFrame();
            for (int rib = 0; rib < Dome.NUM_RIBS; ++rib)
            {
                for (int row = 0; row < Dome.LEDS_PER_RIB; ++row)
                {
                    Color b = cur.GetLedColor(rib, row);
                    Color a = next.GetLedColor(rib, row);

                    Color newColor = new Color();
                    newColor.A = (byte)(a.A * m_CurBlendValue + b.A * m_Reciprocal);
                    newColor.R = (byte)(a.R * m_CurBlendValue + b.R * m_Reciprocal);
                    newColor.G = (byte)(a.G * m_CurBlendValue + b.G * m_Reciprocal);
                    newColor.B = (byte)(a.B * m_CurBlendValue + b.B * m_Reciprocal);

                    result.SetLedColor(rib, row, newColor);
                }
            }

            base.Calculate(dt, cur, next);
            return result;
        }
Esempio n. 11
0
        public override void GenerateNewFrame(float dt)
        {
            AnimationFrame output = new AnimationFrame();

            Color color1 = Color.Red;
            Color color2 = Color.Green;
            Color color3 = Color.Blue;

            switch (m_Offset++ % 3)
            {
                case 0:
                    color1 = Color.Red;
                    color2 = Color.Green;
                    color3 = Color.Blue;
                    break;
                case 1:
                    color1 = Color.Blue;
                    color2 = Color.Red;
                    color3 = Color.Green;
                    break;
                case 2:
                    color1 = Color.Green;
                    color2 = Color.Blue;
                    color3 = Color.Red;
                    break;
            }

            for (int i = 0; i < 12; ++i)
            {
                output.SetRibColor(i * 3 + 0, color1);
                output.SetRibColor(i * 3 + 1, color2);
                output.SetRibColor(i * 3 + 2, color3);
            }

            m_CurrentFrame = output;
        }
Esempio n. 12
0
 public void SetKeyframeOnlyTrans(int index, AnimationFrame frame)
 {
     float* v = (float*)&frame.Translation;
     for (int i = 0x16; i < 0x19; i++)
         SetKeyframe((KeyFrameMode)i, index, *v++);
 }
Esempio n. 13
0
 public void SetKeyframeOnlyRot(int index, AnimationFrame frame)
 {
     float* v = (float*)&frame.Rotation;
     for (int i = 0x13; i < 0x16; i++)
         SetKeyframe((KeyFrameMode)i, index, *v++);
 }
Esempio n. 14
0
 public void SetKeyframeOnlyScale(int index, AnimationFrame frame)
 {
     float* v = (float*)&frame.Scale;
     for (int i = 0x10; i < 0x13; i++)
         SetKeyframe((KeyFrameMode)i, index, *v++);
 }
Esempio n. 15
0
        public static LayeredTileMap FromTiledMapSave(string fileName, string contentManager)
        {
            TiledMapSave tms = TiledMapSave.FromFile(fileName);

            // Ultimately properties are tied to tiles by the tile name.
            // If a tile has no name but it has properties, those properties
            // will be lost in the conversion. Therefore, we have to add name properties.
            tms.NameUnnamedTilesetTiles();


            string directory = FlatRedBall.IO.FileManager.GetDirectory(fileName);

            var rtmi = ReducedTileMapInfo.FromTiledMapSave(
                tms, 1, 0, directory, FileReferenceType.Absolute);

            var toReturn = FromReducedTileMapInfo(rtmi, contentManager, fileName);


            foreach (var mapObjectgroup in tms.objectgroup)
            {
                var shapeCollection = tms.ToShapeCollection(mapObjectgroup.Name);
                if (shapeCollection != null && shapeCollection.IsEmpty == false)
                {
                    shapeCollection.Name = mapObjectgroup.Name;
                    toReturn.ShapeCollections.Add(shapeCollection);
                }
            }

            foreach (var layer in tms.MapLayers)
            {
                var matchingLayer = toReturn.MapLayers.FirstOrDefault(item => item.Name == layer.Name);


                if (matchingLayer != null)
                {
                    if (layer is MapLayer)
                    {
                        var mapLayer = layer as MapLayer;
                        foreach (var propertyValues in mapLayer.properties)
                        {
                            matchingLayer.Properties.Add(new NamedValue
                            {
                                Name = propertyValues.StrippedName,
                                Value = propertyValues.value,
                                Type = propertyValues.Type
                            });
                        }

                        matchingLayer.Visible = mapLayer.visible == 1;
                    }
                }
            }

            foreach (var tileset in tms.Tilesets)
            {
                foreach (var tile in tileset.TileDictionary.Values)
                {
                    if (tile.properties.Count != 0)
                    {
                        // this needs a name:
                        string name = tile.properties.FirstOrDefault(item => item.StrippedName.ToLowerInvariant() == "name")?.value;

                        if (!string.IsNullOrEmpty(name))
                        {
                            List<NamedValue> namedValues = new List<NamedValue>();
                            foreach (var prop in tile.properties)
                            {
                                namedValues.Add(new NamedValue()
                                { Name = prop.StrippedName, Value = prop.value, Type = prop.Type });
                            }

                            toReturn.Properties.Add(name, namedValues);

                        }
                    }
                }
            }

            var tmxDirectory = FileManager.GetDirectory(fileName);

            var animationDictionary = new Dictionary<string, AnimationChain>();

            // add animations
            foreach (var tileset in tms.Tilesets)
            {

                string tilesetImageFile = tmxDirectory + tileset.Images[0].Source;

                if (tileset.SourceDirectory != ".")
                {
                    tilesetImageFile = tmxDirectory + tileset.SourceDirectory + tileset.Images[0].Source;
                }

                var texture = FlatRedBallServices.Load<Microsoft.Xna.Framework.Graphics.Texture2D>(tilesetImageFile);

                foreach (var tile in tileset.Tiles.Where(item => item.Animation != null && item.Animation.Frames.Count != 0))
                {
                    var animation = tile.Animation;

                    var animationChain = new AnimationChain();
                    foreach (var frame in animation.Frames)
                    {
                        var animationFrame = new AnimationFrame();
                        animationFrame.FrameLength = frame.Duration / 1000.0f;
                        animationFrame.Texture = texture;

                        int tileIdRelative = frame.TileId;
                        int globalTileId = (int)(tileIdRelative + tileset.Firstgid);

                        int leftPixel;
                        int rightPixel;
                        int topPixel;
                        int bottomPixel;
                        TiledMapSave.GetPixelCoordinatesFromGid((uint)globalTileId, tileset, out leftPixel, out topPixel, out rightPixel, out bottomPixel);

                        animationFrame.LeftCoordinate = MapDrawableBatch.CoordinateAdjustment + leftPixel / (float)texture.Width;
                        animationFrame.RightCoordinate = -MapDrawableBatch.CoordinateAdjustment + rightPixel / (float)texture.Width;

                        animationFrame.TopCoordinate = MapDrawableBatch.CoordinateAdjustment + topPixel / (float)texture.Height;
                        animationFrame.BottomCoordinate = -MapDrawableBatch.CoordinateAdjustment + bottomPixel / (float)texture.Height;


                        animationChain.Add(animationFrame);
                    }

                    var property = tile.properties.FirstOrDefault(item => item.StrippedNameLower == "name");

                    if (property == null)
                    {
                        throw new InvalidOperationException(
                            $"The tile with ID {tile.id} has an animation, but it doesn't have a Name property, which is required for animation.");
                    }
                    else
                    {
                        animationDictionary.Add(property.value, animationChain);
                    }

                }

            }

            toReturn.Animation = new LayeredTileMapAnimation(animationDictionary);

            toReturn.MapProperties = tms.properties
                .Select(propertySave => new NamedValue
                    { Name = propertySave.name, Value = propertySave.value, Type = propertySave.Type })
                .ToList();


            return toReturn;
        }
Esempio n. 16
0
 // TODO: DamageType - don't know possible values at this time
 // TODO: DamageBox - don't know structure of it at this time
 // TODO: Find out what other settings are possible
 public ConstAnimationFrame(AnimationFrame mutable)
 {
     m_mutable = mutable;
 }
        private void RefreshPage()
        {
            if (_target != null)
            {
                //_currentPage = (int)numFrame.Value - 1;

                _currentFrame = _target.GetAnimFrame(_currentPage);

                numScaleY.Value = _currentFrame.Scale._y;
                //numScaleY.Value = _currentFrame.Scale._y;
                //numScaleZ.Value = _currentFrame.Scale._z;

                numRot.Value = _currentFrame.Rotation._x;
                //numRotY.Value = _currentFrame.Rotation._y;
                //numRotZ.Value = _currentFrame.Rotation._z;

                numTransX.Value = _currentFrame.Translation._x;
                numTransY.Value = _currentFrame.Translation._y;
                //numTransZ.Value = _currentFrame.Translation._z;

                numScaleX.Value = _currentFrame.Scale._x;

                for (int i = 0; i < 9; i++)
                    UpdateBox(i);

                btnPrev.Enabled = _currentPage > 0;
                btnNext.Enabled = _currentPage < (_numFrames - 1);

                listKeyframes.SelectedIndex = FindKeyframe(_currentPage);
            }
        }
        private void UpdateTarget()
        {
            listKeyframes.BeginUpdate();
            listKeyframes.Items.Clear();
            if (_target != null)
            {
                if (_target.FrameCount > 0)
                {
                    AnimationFrame a = new AnimationFrame();
                    bool check = false;
                    for (int x = 0; x < _target.FrameCount; x++)
                    {
                        a = _target.GetAnimFrame(x);
                        a.Index = x;
                        for (int i = 0x10; i < 0x19; i++)
                        {
                            if (_target.GetKeyframe((KeyFrameMode)i, x) != null)
                            {
                                check = true;
                                a.SetBool(i - 0x10, true);
                            }
                        }
                        if (check == true)
                        {
                            a.forKeyframeSRT = true;
                            listKeyframes.Items.Add(a);
                            check = false;
                        }
                    }
                    //foreach (AnimationKeyframe f in _target.Keyframes.Keyframes)
                    //    listKeyframes.Items.Add(f);

                    _numFrames = _target.FrameCount;

                    _currentPage = 0;
                    numFrame.Value = 1;
                    numFrame.Maximum = _numFrames;
                    lblFrameCount.Text = String.Format("/ {0}", _numFrames);
                }
                else
                    numFrame.Value = 1;
            }
            listKeyframes.EndUpdate();

            RefreshPage();
        }
Esempio n. 19
0
        public AnimationFrame ToAnimationFrame(string contentManagerName, bool loadTexture, TextureCoordinateType coordinateType)
        {
            AnimationFrame frame = new AnimationFrame();

            #region Set basic variables

            frame.TextureName = TextureName;
            frame.FrameLength = FrameLength;

            if (loadTexture)
            {
#if FRB_MDX
            frame.Texture = FlatRedBallServices.Load<Texture2D>(TextureName, contentManagerName);

#else

                if (mTextureInstance != null)
                {
                    frame.Texture = mTextureInstance;
                }
                // I think we should tolarte frames with a null Texture
                else if (!string.IsNullOrEmpty(TextureName))
                {
					#if IOS || ANDROID
					frame.Texture = FlatRedBallServices.Load<Texture2D>(TextureName.ToLowerInvariant(), contentManagerName);
					#else
					frame.Texture = FlatRedBallServices.Load<Texture2D>(TextureName, contentManagerName);
					#endif
                    
                }
                //frame.Texture = FlatRedBallServices.Load<Texture2D>(TextureName, contentManagerName);
#endif
            }
            frame.FlipHorizontal = FlipHorizontal;
            frame.FlipVertical = FlipVertical;

            if (coordinateType == TextureCoordinateType.UV)
            {
                frame.LeftCoordinate = LeftCoordinate;
                frame.RightCoordinate = RightCoordinate;
                frame.TopCoordinate = TopCoordinate;
                frame.BottomCoordinate = BottomCoordinate;
            }
            else if (coordinateType == TextureCoordinateType.Pixel)
            {
                // April 16, 2015
                // Victor Chelaru
                // We used to throw this exception, but I don't know why we should, because
                // the Sprite won't show up, and the problem should be discoverable in tools
                // without a crash
                //if (frame.Texture == null)
                //{
                //    throw new Exception("The frame must have its texture loaded to use the Pixel coordinate type");
                //}

                if (frame.Texture != null)
                {
                    frame.LeftCoordinate = LeftCoordinate / frame.Texture.Width;
                    frame.RightCoordinate = RightCoordinate / frame.Texture.Width;

                    frame.TopCoordinate = TopCoordinate / frame.Texture.Height;
                    frame.BottomCoordinate = BottomCoordinate / frame.Texture.Height;
                }
            }
            
            
            frame.RelativeX = RelativeX;
            frame.RelativeY = RelativeY;

            #endregion

            return frame;
        }
 private void CalculateOrigin(AnimationFrame f)
 {
     if (f.align == AligningMode.None)
     {
         currentOrigin = f.center;
     }
     else
     {
     #if WINDOWS_PHONE
         if (((int)f.align & (int)AligningMode.Center) != 0)
     #else
         if (f.align.HasFlag(AligningMode.Center))
     #endif
         {
             currentOrigin.X = f.rect.Width / 2;
             currentOrigin.Y = f.rect.Height / 2;
         }
     #if WINDOWS_PHONE
         if (((int)f.align & (int)AligningMode.Left) != 0)
     #else
         if (f.align.HasFlag(AligningMode.Left))
     #endif
         {
             currentOrigin.X = 0;
         }
     #if WINDOWS_PHONE
         else if (((int)f.align & (int)AligningMode.Right) != 0)
     #else
         else if (f.align.HasFlag(AligningMode.Right))
     #endif
         {
             currentOrigin.X = f.rect.Width;
         }
     #if WINDOWS_PHONE
         if (((int)f.align & (int)AligningMode.Top) != 0)
     #else
         if (f.align.HasFlag(AligningMode.Top))
     #endif
         {
             currentOrigin.Y = 0;
         }
     #if WINDOWS_PHONE
         else if (((int)f.align & (int)AligningMode.Bottom) != 0)
     #else
         else if (f.align.HasFlag(AligningMode.Bottom))
     #endif
         {
             currentOrigin.Y = f.rect.Height;
         }
     }
 }
Esempio n. 21
0
        private IAnimationFrame[] LoadAnimation(BinaryFileReader reader, AnimationFrame.SittingTransformation sitting)
        {
            ushort[] palette = GetPalette(reader); // 0x100 * 2 = 0x0200 bytes
            int read_start = (int)reader.Position; // save file position after palette.

            int frameCount = reader.ReadInt(); // 0x04 bytes

            int[] lookups = new int[frameCount]; // frameCount * 0x04 bytes
            for (int i = 0; i < frameCount; ++i) { lookups[i] = reader.ReadInt(); }

            IAnimationFrame[] frames = new AnimationFrame[frameCount];
            for (int i = 0; i < frameCount; ++i)
            {
                if (lookups[i] < lookups[0])
                {
                    frames[i] = AnimationFrame.Empty; // Fix for broken animations, per issue13
                }
                else
                {
                    reader.Seek(read_start + lookups[i], SeekOrigin.Begin);
                    frames[i] = new AnimationFrame(m_Graphics, palette, reader, sitting);
                }
            }
            return frames;
        }
 public AnimationFrame GetFullFrame(int index, bool linear)
 {
     AnimationFrame frame = new AnimationFrame() { Index = index };
     float* dPtr = (float*)&frame;
     for (int x = 0x10; x < 0x19; x++)
     {
         frame.SetBool(x - 0x10, GetKeyframe((KeyFrameMode)x, index) != null);
         *dPtr++ = GetFrameValue((KeyFrameMode)x, index, linear, false);
     }
     return frame;
 }
 public void AddFrame(int x, int y, int w, int h, string center)
 {
     AnimationFrame f = new AnimationFrame();
     f.rect = new Rectangle(x, y, w, h);
     f.align = AligningMode.None;
     if (center.Contains("center"))
         f.align |= AligningMode.Center;
     if (center.Contains("left"))
         f.align |= AligningMode.Left;
     if (center.Contains("right"))
         f.align |= AligningMode.Right;
     if (center.Contains("top"))
         f.align |= AligningMode.Top;
     if (center.Contains("bottom"))
         f.align |= AligningMode.Bottom;
     if (f.align == AligningMode.None)
     {
         string[] coord = center.Split('_');
         f.center.X = (float)Convert.ToDouble(coord[0]);
         f.center.Y = (float)Convert.ToDouble(coord[1]);
     }
     frameRects.Add(f);
 }