Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

217
Vistas
For bucle donde cada valor se distribuye correctamente

Tengo un bucle for en el que quiero distribuir una cierta cantidad de palabras con la misma longitud en una línea de tiempo.

Tengo variables que me dan la duración de cada texto, el inicio de donde se generarán las palabras y el final.

 var wordArray = []; for (t = 0; t < words.length; t++) { //This generates the textbox wordArray[wordArray.length] = currentComp.layers.addText(words[t]); if (t == 0) { //This makes the first textbox appear in the start wordArray[wordArray.length - 1].inPoint = start; //This makes the first textbox have the length with the value that divides it by the number of words wordArray[wordArray.length - 1].outPoint = wordArray[wordArray.length - 1].inPoint + textTime; //Here I am trying to make them all evenly distributed by multiplying the divided duration for the number of words that are already existing } else if (t < words.length - 2) { wordArray[wordArray.length - 1].inPoint = start + textTime * (wordArray.length - 1); wordArray[wordArray.length - 1].outPoint = end - textTime * (wordArray.length - 1); } else { //This is here to make the last word stop at the end of the text duration. wordArray[wordArray.length - 1].inPoint = start + textTime * (wordArray.length - 1); wordArray[wordArray.length - 1].outPoint = wordArray[wordArray.length - 1].inPoint + textTime; } }

El error viene al final, como se ve en la imagen. La palabra del final (resaltada en blanco) tiene menos longitud que la anterior, y la penúltima palabra tiene más longitud que todas las demás.

Soy consciente de que esto no es un problema de sintaxis, sino un problema matemático que parece que no puedo resolver. Gracias por adelantado

EDITAR: Encontré la respuesta y actualicé la sintaxis para que coincida.

La palabra al final (resaltada en blanco) tiene menos longitud que la anterior, y la penúltima palabra tiene más longitud que todas las demás palabras

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Actualicé la sintaxis para que coincida con el código correcto.

Resulta que el problema era que el espacio para cada palabra no se calculaba correctamente.

Lo hice funcionar calculando el inicio y el final de cada sección haciendo esto:

 var startDurationString = timeCalc[0].split(":"); var finalStartDurationString = startDurationString[1] + ":" + startDurationString[2] + ":" + startDurationString[3]; var startDuration = currentFormatToTime(finalStartDurationString, currentComp.frameRate); var endDurationString = timeCalc[1].split(":"); var finalEndDurationString = endDurationString[1] + ":" + endDurationString[2] + ":" + endDurationString[3]; var endDuration = currentFormatToTime(finalEndDurationString, currentComp.frameRate);

Luego, usé la diferencia del principio y el final y lo dividí por la longitud de las palabras.

 durationForEachText = (endDuration-startDuration) / numberOfWords.length;

Espero que ayude a alguien por ahí.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda