sprite walk animation images code example

Example 1: css image sprites

/******************** How to use image sprites? ************************/
/* For this, you need to position the image so that only a segment of it 
is revealed. This technique also allows you to zoom in on parts of the 
image */

<html>
  <head>
    <meta charset="UTF-8" />
    <title> Title </title>
    <style>

      #window_1 {
        height: 120px;
        width: 117px;
        background: url("image_path") 0px 0px; /* coordinates of the upper left point: x = 0 and y = 0 */
      }

      #window_2 {
        height: 150px;
        width: 100px;
        background: url("image_path") -300px -200px; /* coordinates of the upper left point: x = -300 and y = -200 (we use negative numbers) */
      }

    </style>
  </head>
  <body>

    <div id="window_1"></div>
    <div id="window_2"></div>

  </body>
</html>

Example 2: animate sprite sheet unity in code

[SerializeField] Animator anim;
//must drag in the animator that you are using

public void StartAnimation()
{
	//can be a float, int, bool, or trigger
    //string is the name of the parameter in the animator
	anim.SetBool("isAttacking", true);
}

Tags:

Css Example