Whilst coding a canvas game, I ran into a problem.
It would be a doll if a nice english-muffin-eater like you could help me with said glitch.
In a nutshell, I have an array of coordinates. I need to draw copies of the image onto the canvas with the coordinates in the array.
It would be something like this:
- Code: Select all
ctx.drawImage(castle, castles.x[1], castles.y[1]);
ctx.drawImage(castle, castles.x[2], castles.y[2]);
ctx.drawImage(castle, castles.x[3], castles.y[3]);
The only problem with that is that a new pair of coordinates is added every time the loop comes around. Any suggestions?
something like:
- Code: Select all
ctx.drawImage(castle, castles.x[every item], castles.y[every item]);
I have been told it could be accomplished with a for loop, but it didn't work:
- Code: Select all
for (i=1; i==castles.x.length; i++){
ctx.drawImage(castle, castles.x[i], castles.y[i]);
}
but that didn't work.
Help would be appreciated
-[randomletters]