This site requires JavaScript, please enable it in your browser!
Greenfoot back
dlanni
dlanni wrote ...

2012/5/13

Animation Problems

dlanni dlanni

2012/5/13

#
For our final project, we are to animate our characters. I looked at the Support Classes and the first one "AnimatedActor" looked useful...until I got to the next to last line : public void act() { currentImage = (currentImage + 1) % images.length; setImage(images); } What does "%images.length;" refer to? I am using 4 images; am I supposed to plug 25% in that spot?
matt.milan matt.milan

2012/5/13

#
basically prevents currentImage from ever being a number outside of the array's size if the array were length 5 and currentImage was 17 + 1, it'd be 18 % 5, or 3. % only returns the remainder of integer division. doesnt work for doubles etc, i think.
dlanni dlanni

2012/5/13

#
Hey, Matt. I was looking at your project--wow, you put a lot of work into it! Thanks for replying, but I'm still unclear what number or info or what I'm supposed to insert at that % spot. It looks like I'm not supposed to insert anything there, just type it in verbatim.
danpost danpost

2012/5/14

#
@dlanni, if you are using 4 images, then use:
currentImage = (currentImage + 1) % 4;
This statement when repeated produces values of { 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, etc. }. Basically, every time 'currentImage + 1' becomes 4, the result is 0 again. Anyway, with these results, you can repeatedly rotate through your array of images.
matt.milan matt.milan

2012/5/14

#
the number i would put there would be the number of images you have. images.length = size of the array of images = how many images you have does that help?
dlanni dlanni

2012/5/14

#
Thanks, guys!
You need to login to post a reply.