Hello,
I'm trying to add multiple objects at once with arrays. I currently have 3 arrays, 1 for the images, and separate arrays for the coordinates. The Following code obviously doesn't work because the addObject(obstakel, xCoords, yCoords); is wrong. What is the proper way of doing this? Thanks in advance!
Aermus
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | public class Stad extends World { private String[] img = { "Gebouw1.jpg" , "Gebouw2.jpg" , "Gebouw3.jpg" , "Gebouw4.jpg" , "Gebouw5.jpg" , "Gebouw6.jpg" , "Gebouw7.jpg" , "Gebouw8.jpg" , "Gebouw9.jpg" , "Gebouw10.jpg" , "Gebouw11.jpg" , "Gebouw12.jpg" , "Gebouw13.jpg" , "Gebouw14.jpg" , "Gebouw15.jpg" , "Gebouw16.jpg" , "Gebouw17.jpg" , "Gebouw18.jpg" , "Gebouw19.jpg" , "Gebouw20.jpg" , "Gebouw21.jpg" , "Gebouw22.jpg" , "Gebouw23.jpg" }; private String[] xCoords = { "799" , "20" , "1419" , "1038" , "503" , "1556" , "1353" , "1336" , "1354" , "514" , "661" , "713" , "767" , "861" , "240" , "1354" , "462" , "711" , "1114" , "124" , "367" , "272" , "1249" }; private String[] yCoords = { "37" , "383" , "166" , "352" , "279" , "566" , "324" , "370" , "418" , "455" , "424" , "825" , "424" , "455" , "506" , "598" , "556" , "597" , "649" , "784" , "784" , "800" , "814" }; public Stad(){ super ( 1600 , 875 , 1 ); PlaatsObstakels(); } public void PlaatsObstakels(){ for ( int i = 0 ; i < img.length; i++) { Obstakel obstakel = new Obstakel(); addObject(obstakel, xCoords[i], yCoords[i]); } } } |