Question

I'm trying to store 'y' coordinates for an image in an array and cycle through them on click.

I've stored the coordinates in an array and the event listener obediently changes

The y coordinate of my image but using the array index rather than the given values.

for example 0,1,2,3 instead of 50 -50 -150 -250

posa = 50;
posb = -50;
posc = -150;
posd = -250;

position  = [posa, posb, posc, posd];

index = 0;

clue1.addEventListener("click", function(event) {

//clue1.y = posb;     //works

clue1.y = (index++)%(position.length);

//alert(position);   //returns 50 -50 -150 -250

//alert(clue1.y):    //returns 0 1 2 3 (the y position of my image)

stage.update();

});   

Many thanks to those who take a look

Was it helpful?

Solution

try the following

clue1.y = position[(index++)%(position.length)];

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top