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

2013/1/6

Making loop for an animation of 100 images in series

camsterb camsterb

2013/1/6

#
for(int i=0;i<119;i++) setImage("movie++i++.png"); I have 118 different frames for a brief animation. I want to play them through a loop. Each frame is called "movieX.png" where X represents numbers 0-118. I don't quite know how to do this or if it can be done. Other general advice for simplifying my code is a great help too. Thank you.
Oxy Oxy

2013/1/6

#
Ok i see what your trying to do where each loop when the i in the loop goes up it goes up in the image so match it, well the main thing i see wrong is the loop see's it as playing "movie++i++.png" with that specific name. im assuming your not even seeing your first image you need to end quotes then start them again for the i so it would be ( if the ++ is part of the name of the image.) "movie++" + i + "++.png" because in this way, i is now a variable, the way you have makes it part of the String. I'm not sure the loop your trying to accomplish is possible, but i like the idea. so yeah, try for(int i = 0; i<119; i++) setImage("movie++" + i + "++.png"); Good luck
Oxy Oxy

2013/1/6

#
if that doesn't work you may need an Array of Strings..
String[] str = new String[119];
for (int i = 0; i < str.length; i++){
        str[i] = "movie++" + i + "++.png";
        setImage(str[i]);
}


//that str.length may need to be str.length() can't remember.
I have tested making a location of a picture into a string (like above) then placing it in setImage and it does work. and if you location is not movie++#++.png and its movie#.png, then just take out the ++ withen the quotes in the above code
camsterb camsterb

2013/1/6

#
Hi. Yep, just putting in +i+ between closed quotations worked very nicely. Thanks a lot for the clarification and the hard work as always! :D
You need to login to post a reply.