Esempio n. 1
0
 /// <summary>
 /// Update animations if currently playing.
 /// </summary>
 /// <param name="elapsedTime">Elapsed game time, in seconds, since last frame.</param>
 public void Update(float elapsedTime)
 {
     if (_currAnimation != null)
     {
         int index = _currAnimation.Update(elapsedTime);
         _spritesheetStep = Spritesheet.GetStep(index);
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Copy spritesheet step from other sprite.
 /// </summary>
 /// <param name="other">Other sprite to copy step from.</param>
 public void CopyStep(SpriteEntity other)
 {
     _spritesheetStep = other._spritesheetStep;
     if (other._currAnimation != null)
     {
         PlayAnimation(other._currAnimation.Clip, other._currAnimation.SpeedFactor, other._currAnimation.CurrentStep);
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Create the sprite entity.
        /// </summary>
        /// <param name="spritesheet">Spritesheet for this sprite.</param>
        /// <param name="material">Material to use for this sprite.</param>
        public SpriteEntity(SpriteSheet spritesheet, Materials.MaterialAPI material) : base()
        {
            // store spritesheet and material
            Spritesheet = spritesheet;
            _material   = material;

            // set default rendering queue
            RenderingQueue = RenderingQueue.Billboards;

            // set default step
            _spritesheetStep = spritesheet.GetStep(0);
        }
Esempio n. 4
0
        /// <summary>
        /// Define a step in the spritesheet.
        /// </summary>
        /// <param name="position">Position in spritesheet texture, in percents (eg values range from 0 to 1).</param>
        /// <param name="size">Size in spritesheet texture, in percents (eg values range from 0 to 1).</param>
        /// <param name="identifier">Optional step string identifier.</param>
        public void AddStep(Vector2 position, Vector2 size, string identifier = null)
        {
            // create the step
            SpriteSheetStep step = BuildStep(position, size);

            _steps.Add(step);

            // if there's a string identifier, set it
            if (identifier != null)
            {
                _stepsIdentifierToIndex[identifier] = _steps.Count - 1;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Create a single spritesheet step.
        /// </summary>
        /// <param name="positionInSpritesheet">Position in spritesheet (0-1 coords).</param>
        /// <param name="sizeInSpriteSheet">Size in spritesheet (0-1 coords).</param>
        SpriteSheetStep BuildStep(Vector2 positionInSpritesheet, Vector2 sizeInSpriteSheet)
        {
            // create vertices
            VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[4];

            // set normal
            for (int i = 0; i < 4; ++i)
            {
                vertices[i].Normal = Vector3.Forward;
            }

            // set vertices position and UV
            float halfSize = 0.5f;

            vertices[0].Position = new Vector3(-halfSize, -halfSize, 0);    // bottom left
            vertices[1].Position = new Vector3(-halfSize, halfSize, 0);     // top left
            vertices[2].Position = new Vector3(halfSize, -halfSize, 0);     // bottom right
            vertices[3].Position = new Vector3(halfSize, halfSize, 0);      // top right

            // set vertices UVs
            vertices[0].TextureCoordinate = positionInSpritesheet + sizeInSpriteSheet;                              // bottom left
            vertices[1].TextureCoordinate = positionInSpritesheet + new Vector2(sizeInSpriteSheet.X, 0);            // top left
            vertices[2].TextureCoordinate = positionInSpritesheet + new Vector2(0, sizeInSpriteSheet.Y);            // bottom right
            vertices[3].TextureCoordinate = positionInSpritesheet;                                                  // top right

            // Set the index buffer for each vertex, using clockwise winding
            short[] indexes = new short[6];
            indexes[0] = 0;
            indexes[1] = 1;
            indexes[2] = 2;
            indexes[3] = 2;
            indexes[4] = 1;
            indexes[5] = 3;

            // create a new step and add to steps dictionary
            SpriteSheetStep step = new SpriteSheetStep();

            step.Vertices = vertices;
            step.Indexes  = indexes;
            return(step);
        }
Esempio n. 6
0
 /// <summary>
 /// Set spritesheet step from index.
 /// </summary>
 /// <param name="index">Step index to set.</param>
 public void SetStep(int index)
 {
     _spritesheetStep = Spritesheet.GetStep(index);
     _currAnimation   = null;
 }
Esempio n. 7
0
 /// <summary>
 /// Set spritesheet step from string identifier.
 /// </summary>
 /// <param name="identifier">Step identifier (must be set in spriteshet).</param>
 public void SetStep(string identifier)
 {
     _spritesheetStep = Spritesheet.GetStep(identifier);
     _currAnimation   = null;
 }
Esempio n. 8
0
 /// <summary>
 /// Change the spritesheet and current step of this sprite.
 /// </summary>
 /// <param name="newSpritesheet">New spritesheet data to use.</param>
 /// <param name="startingStep">Step to set from new spritesheet.</param>
 public void ChangeSpritesheet(SpriteSheet newSpritesheet, int startingStep = 0)
 {
     Spritesheet      = newSpritesheet;
     _spritesheetStep = Spritesheet.GetStep(startingStep);
     _currAnimation   = null;
 }