Foros del Web » Creando para Internet » HTML »

Rendimiento muy lento en HTML5?

Estas en el tema de Rendimiento muy lento en HTML5? en el foro de HTML en Foros del Web. Hola que tal buen dia, Hace unos dias que me llamo la atencion las caracteristicas de HTML5 y me dicidi a hacer un ejercicio para ...
  #1 (permalink)  
Antiguo 04/04/2012, 16:26
 
Fecha de Ingreso: julio-2011
Ubicación: Zapopan, Jal. MX
Mensajes: 316
Antigüedad: 12 años, 9 meses
Puntos: 32
Pregunta Rendimiento muy lento en HTML5?

Hola que tal buen dia,

Hace unos dias que me llamo la atencion las caracteristicas de HTML5 y me dicidi a hacer un ejercicio para probar el power de HTML5, en fin, hice unas pelotas que rebotan entre si mismas y al chocar a los lados.

Me di cuenta que al poner mas de 5 pelotas se empieza a poner muy lento el movimiento de las pelotas, sucede exactamente lo mismo como cuando hice esto solamente con javascript sin usar HTML5.

Entonces me puse a buscar ejemplos de HTML5 en internet y encontre uno parecido al mio, es decir, pelotas que robotan entre si, la diferencia de este es que no se dismunuye nada el rendimiento y eso que tenia como 100 pelotas! Incluso puse 200 y tampoco se afectaba el rendimiento.

No entiendo por que conmigo se disminuye el rendimiento con solo poner 5 pelotas y en ese ejemplo y otros similares hasta con increibles efectos 3d y sin nada de lentitud!

En fin, parece que el problema surge al hacer los ciclos para cada pelota, pero es algo que debe hacerse si no no le veo otra alternativa.

Sin mas les dejo mi script para que me digan que estoy aplicando mal en HTML5, espero puedan entenderle no es mucho.
  #2 (permalink)  
Antiguo 04/04/2012, 16:30
 
Fecha de Ingreso: julio-2011
Ubicación: Zapopan, Jal. MX
Mensajes: 316
Antigüedad: 12 años, 9 meses
Puntos: 32
Respuesta: Rendimiento muy lento en HTML5?

Ha, no me deja ponerlo arriba asi que aqui pongo el codigo.
Código Javascript:
Ver original
  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" lang="es">
  3. <head>
  4.     <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
  5.     <title></title>
  6.     <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
  7.     <script type="text/javascript">
  8.         $(function(){
  9.             var MyBalls = new balls("balls");
  10.             MyBalls.$canvas.resizable();
  11.             for( var i = 0; i < 10; i++ ) {
  12.                 MyBalls.create(
  13.                 (i+1) * 60,
  14.                 50,
  15.                 3 * (i+1),
  16.                 'rgb('+(100+parseInt(Math.random()*151))+', '+(100+parseInt(Math.random()*151))+', '+(100+parseInt(Math.random()*151))+')' );
  17.             }
  18.             setInterval(function() {
  19.                 $.each( MyBalls.balls, function(i_ball, ball) {
  20.                     ball.move();
  21.                 } );
  22.             }, 1);
  23.         });
  24.         var balls = function( id ) {
  25.             this.$canvas = $("#"+id);
  26.             this.context = this.$canvas[0].getContext("2d");
  27.             this.balls = [];
  28.         };
  29.         balls.prototype = {
  30.             create: function(CENTERX, CENTERY, RADIUS, COLOR, NO_NEW) {
  31.                 var Context = this.context;
  32.                 var This = this;
  33.                 Context.beginPath();
  34.                 Context.arc(CENTERX, CENTERY, RADIUS, 0, 2*Math.PI);
  35.                 Context.closePath();
  36.                 Context.strokeStyle = COLOR;
  37.                 Context.fillStyle = COLOR;
  38.                 Context.stroke();
  39.                 Context.fill();
  40.                 if ( NO_NEW ) {
  41.                     return;
  42.                 }
  43.                 var BallConstructor   = function() {
  44.                     this.centerX = CENTERX;
  45.                     this.centerY = CENTERY;
  46.                     this.radius  = RADIUS;
  47.                     this.color   = COLOR;
  48.                     this.dirX = 1;
  49.                     this.dirY = 1;
  50.                     this.speed= 1;
  51.                 };
  52.                 BallConstructor.prototype = {
  53.                     coords: function() {
  54.                         return {
  55.                             x1: this.centerX - this.radius,
  56.                             x2: this.centerX + this.radius,
  57.                             y1: this.centerY - this.radius,
  58.                             y2: this.centerY + this.radius,
  59.                             minX: 0,
  60.                             maxX: This.$canvas.width(),
  61.                             minY: 0,
  62.                             maxY: This.$canvas.height()
  63.                         }
  64.                     },
  65.                     move: function( SPEED, DIR ) {
  66.                         this.speed = SPEED || 1;
  67.                         this.dir = DIR || 1;
  68.                         var coords = this.coords();
  69.                         var axis = [
  70.                             ['x', 'X'],
  71.                             ['y', 'Y']
  72.                         ];
  73.                         for ( var i=0; i<2; i++ ) {
  74.                             var invert = false;
  75.                             var ax = axis[i][0];
  76.                             var AX = axis[i][1];
  77.                             var axis1 = coords[ax+'1'];
  78.                             var axis2 = coords[ax+'2'];
  79.                             var min_axis = coords['min'+AX];
  80.                             var max_axis = coords['max'+AX];
  81.                             var ThisBall = this;
  82.                             var prevcenter = this['center'+AX];
  83.                             var forward = this['dir'+AX] === 1 ? true : false;
  84.                             if ( axis1 - this.speed <= min_axis && !forward ) {
  85.                                 prevcenter = min_axis + this.radius;
  86.                                 invert = true;
  87.                             }
  88.                             if ( axis2 + this.speed >= max_axis && forward ) {
  89.                                 prevcenter = max_axis - this.radius;
  90.                                 invert = true;
  91.                             }
  92.                             $.each( This.balls, function(i_ball, that_ball) {
  93.                                 if ( ThisBall == that_ball ) {
  94.                                     return 'continue';
  95.                                 }
  96.                                 var that_coords = that_ball.coords();
  97.                                 var cond1 = coords.x1 - ThisBall.speed <= that_coords.x2;
  98.                                 var cond2 = coords.x2 + ThisBall.speed >= that_coords.x1;
  99.                                 var cond3 = coords.y1 - ThisBall.speed <= that_coords.y2;
  100.                                 var cond4 = coords.y2 + ThisBall.speed >= that_coords.y1;
  101.                                 if ( cond1 && cond2 && cond3 && cond4 ) {
  102.                                     invert = true;                                
  103.                                 }
  104.                             } );
  105.                             this['center'+AX] = prevcenter;
  106.                             if ( invert ) {
  107.                                 this['dir'+AX] *= -1;  
  108.                             }
  109.                             }
  110.                         this.centerX += this.speed * this.dirX;
  111.                         this.centerY += this.speed * this.dirY;
  112.                         This.clear();
  113.                        
  114.                         $.each( This.balls, function( i, ball ) {
  115.                             This.create(ball.centerX, ball.centerY, ball.radius, ball.color, true);
  116.                         });
  117.                     }
  118.                 };
  119.                 var BallObject = new BallConstructor;
  120.                 this.balls.push(BallObject);
  121.                 return BallObject;
  122.             },
  123.             clear: function() {
  124.                 this.context.clearRect(
  125.                     0, 0, this.$canvas.width(), this.$canvas.height()
  126.                 );
  127.             }
  128.         };
  129.     </script>
  130. </head>
  131. <body>
  132.     <canvas id="balls" width="800" height="400" style="border: 1px solid #000">
  133.    
  134.     </canvas>
  135. </body>
  136. </html>
  #3 (permalink)  
Antiguo 11/08/2012, 09:59
Avatar de lucasmoyano  
Fecha de Ingreso: enero-2010
Mensajes: 75
Antigüedad: 14 años, 3 meses
Puntos: 10
Respuesta: Rendimiento muy lento en HTML5?

Hola amigo!! Probe tu ejemplo en FF IE Chrome y safari pero no me andubo... yo probe crear un framework de html5, probe con cocos2d (http://cocos2d-javascript.org/) y easejs (http://easejs.org/) y tuve el mismo resultado... el perfomance muy lento =/
  #4 (permalink)  
Antiguo 04/09/2012, 11:14
 
Fecha de Ingreso: julio-2011
Ubicación: Zapopan, Jal. MX
Mensajes: 316
Antigüedad: 12 años, 9 meses
Puntos: 32
Respuesta: Rendimiento muy lento en HTML5?

Hola amigo, lo que pasa es que se me paso incluir la libreria UI de jQuery, ya que en la línea 10, utilizo la interacción resizable() de esa libreria, solo borrala y verás el ejemplo funcionando. Pero a lo mismo que voy, es que nunca he logrado hacer que muchos objetos (ya ni pocos) anden sin afectar gravemente el rendimiento, por más que veo ejemplos siempre hago una basura de lentitud haha.
Checare el cocos2d, gracias.
Por cierto, prueba la version 1.8 de jQuery, esta ya trabaja perfectamente con HTML5 y que el rendimiento en todos los aspectos es mucho más rápido, ya sea con efectos, animaciones, etc. pues el core fue reconstruido desde cero. Saludos!

Etiquetas: html5, lento, rendimiento
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 02:38.