0

I'm making small games in C# for fun, and used a guide on youtube to help me in the process. However, I use some of the code the youtuber shows, but there's a bit of it, I don't understand completely.

index++;

//gif animations
if (right == true && index % 15 == 0)
{
    player.Image = Image.FromFile("char_right.gif");
}
if (left == true && index % 15 == 0)
{
    player.Image = Image.FromFile("char_left.gif");
}

I know that I can change the "% 15" values, and choose how much of my .gif file should be played, during the game, but I'm not sure how the operater "index++" make it work. "index" is defined:

int index = 0;

Can anyone please explain it to me, as I don't want to use something, I don't completely understand :)

Thanks in advance

aloisdg
  • 22,270
  • 6
  • 85
  • 105
  • 1
    What part specifically don't you understand? The [Increment Operator (++)](https://msdn.microsoft.com/en-us/library/36x43w8w.aspx) increments `index` by one... – CodeCaster Jul 07 '15 at 09:55
  • it's mostly how index++ works in the line: if (right == true && index % 15 == 0) Not sure what "index % 15 == 0" do, which is so important for the animation – Tobias Jensen Jul 07 '15 at 09:59
  • 1
    In addition to CodeCaster link, see the [modulus operator "%"](http://stackoverflow.com/questions/10065080/mod-explanation) which returns the rest of an integer division – Binkan Salaryman Jul 07 '15 at 09:59
  • 1
    @BinkanSalaryman Mmh, there's really a `x++` tag. People should really start to read the tag descriptions when asking a question- – sloth Jul 07 '15 at 10:00

0 Answers0