示例#1
0
        public Sprite(System.IO.BinaryReader r)
        {
            // 2 Load texture
            //ushort width = r.ReadUInt16();
            //ushort height = r.ReadUInt16();
            //byte[] colorData = r.ReadBytes(width * height * 4);
            //texture = new Texture2D(Game1.graphics.GraphicsDevice, width, height);
            //texture.SetData(colorData);

            // 3 Load position
            position.X = r.ReadSingle();
            position.Y = r.ReadSingle();

            // 4 Load rotation
            rotation = r.ReadSingle();

            // 5 Load textureKey
            byte length = r.ReadByte();
            textureKey = new string(r.ReadChars(length));
            baseTexture = Repainter.GetTextureCopy(Library.textures[textureKey]);
            texture = baseTexture;

            // 6 Load layer
            layer = r.ReadSingle();

            // Set other data
            baseOrigin = new Vector2(baseTexture.Width / 2, baseTexture.Height / 2);
            origin = baseOrigin;
            needsRedraw = true;
            identifier = SaveFileManager.SaveTypeIdentifier.Sprite;
            color = Color.White;
            IsDead = false;

            Console.WriteLine(ToString() + " loaded at position: " + position.ToString());
        }
示例#2
0
 public Sprite(Vector2 position, string textureKey, float layer)
 {
     // Create copy of texture because this class may change it's own instance
     rotation = 0;
     this.textureKey = textureKey;
     texture = Repainter.GetTextureCopy(Library.textures[textureKey]);
     baseTexture = texture;
     baseOrigin = new Vector2(texture.Width / 2, texture.Height / 2);
     origin = baseOrigin;
     this.position = position;
     needsRedraw = false;
     identifier = SaveFileManager.SaveTypeIdentifier.Sprite;
     color = Color.White;
     IsDead = false;
 }