These forums are currently read-only due to receiving more spam than actual discussion. Sorry.

It is currently Sat Dec 02, 2017 4:12 pm Advanced search

Drawing images from array

If you are stuck or have questions regarding HTML or other Web technologies, ask your questions here. No question too dumb!

Drawing images from array

Postby adtykfhyipoh » Sun Oct 09, 2011 10:52 pm

Good day everyone,
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]
adtykfhyipoh
<h6>
 
Posts: 2
Joined: Sun Oct 09, 2011 10:43 pm

Re: Drawing images from array

Postby zcorpan » Mon Oct 17, 2011 9:06 pm

How does it not work?
zcorpan
<article>
 
Posts: 807
Joined: Tue Feb 06, 2007 8:29 pm
Location: Sweden


Return to Help & Advice

Who is online

Users browsing this forum: No registered users and 1 guest