Sort from right to left in Canvas

0

I have this for which I put some images from left to right.

with this arrangement.

arrText = [435, 820, 795, 915];
var scala = 7.5;


    if (check.checked & Bminus == '1') {
    for (var i = 0; i < arrText.length; i++) {
    parseFloat(arrText[i]);
    distancia = (arrText[i] + (aux)) / scala;
    distancia = parseInt(distancia);
    distanciaPosicion = distancia;
    sumPosicion = (distanciaPosicion + 60);
    sumPosicion = parseInt(sumPosicion);
    aux = aux + arrText[i];
    var image = document.getElementById('screem');
    ctx.drawImage(image, sumPosicion, 67); 
     }
    }

What I am trying to do is to place them on the canvas from right to left, that is, to put the image on the contrary

    
asked by Eduard 29.04.2017 в 17:41
source

2 answers

0

iterates to the reverse:

if (check.checked & Bminus == '1') {
    for (var i = arrText.length-1; i >= 0; i--) {
       parseFloat(arrText[i]);
       distancia = (arrText[i] + (aux)) / scala;
       distancia = parseInt(distancia);
       distanciaPosicion = distancia;
       sumPosicion = (distanciaPosicion + 60);
       sumPosicion = parseInt(sumPosicion);
       aux = aux + arrText[i];
       var image = document.getElementById('screem');
       ctx.drawImage(image, sumPosicion, 67); 
   }
}

arrText = [435, 820, 795, 915];
  for (var i = arrText.length-1; i >= 0; i--) {
      console.log(arrText[i]);
  }
    
answered by 29.04.2017 / 20:55
source
0

reverse the order of your array

arrText = [435, 820, 795, 915]

console.log(arrText);

arrText=arrText.reverse();

console.log(arrText);
    
answered by 29.04.2017 в 20:56