Loading...
Logo
Processing Forum

Bad frameRate

in Programming Questions  •  1 year ago  
Does anyone know why this simple program drops my frameRate to 20-25? Am I missing something?
Copy code
  1. float ballX, ballY;
  2. float speedX = 7;
  3. float speedY = 5;
  4. int dirX = 1;
  5. int dirY = 1;

  6. void setup() {
  7.   size(900, 600, P3D);
  8.   background(200);
  9.   smooth();
  10.   noFill();
  11.   //noStroke();
  12.   //noCursor();
  13.   camera(
  14.   width/2.0, 600, 500,
  15.   width/2.0, height/2, -200,
  16.   0, 1, 0);

  17.   ballX = width/2;
  18.   ballY = height/2;
  19. }

  20. void draw() {
  21.   background(200);
  22.  
  23.   //Creates floor
  24.   fill(255);
  25.   rect(0, 0, 900, 600);

  26.   //Creates top wall
  27.   pushMatrix();
  28.   translate(width/2, -100/2, 50/2);
  29.   fill(150);
  30.   box(width + 400, 100, 50);
  31.   popMatrix();

  32.   //Creates sphere
  33.   ballX += speedX * dirX;
  34.   ballY += speedY * dirY;
  35.   pushMatrix();
  36.   translate(ballX, ballY, 6);
  37.   fill(50);
  38.   sphere(6);
  39.   popMatrix();

  40.   //Creates paddle 1
  41.   pushMatrix();
  42.   translate(60, mouseY, 15/2+5);
  43.   fill(255, 0, 0);
  44.   box(15, 60, 15);
  45.   popMatrix();

  46.   //Creates paddle 2
  47.   pushMatrix();
  48.   translate(width - 60, mouseY, 15/2+5);
  49.   fill(0, 0, 255);
  50.   box(15, 60, 15);
  51.   popMatrix();
  52.  
  53.   if (ballX >= width || ballX <= 0)
  54.     dirX *= -1;
  55.  
  56.   if (ballY >= height || ballY <= 0)
  57.     dirY *= -1;
  58.    
  59.   println(frameRate);
  60. }

EDIT: Oddly enough, commenting out smooth() increases FPS by 30+... :/

If anyone knows anyway to get it to run faster I'd really appreciate it.

Replies(4)

Re: Bad frameRate

1 year ago
Even just this will drop it down to 25-30 fps...?
Copy code
  1. int ballSize = 15;
  2. float ballX, ballY;
  3. float speedX = 7;
  4. float speedY = 5;
  5. int dirX = 1;
  6. int dirY = 1;

  7. void setup() {
  8.   size(900, 600, P3D);
  9.   background(200);
  10.   smooth();
  11.   //noStroke();
  12.   //noCursor();
  13.   camera(width/2.0, 600, 500,
  14.   width/2.0, height/2, -200,

  15.   0, 1, 0);
  16.   ballX = width/2;
  17.   ballY = height/2;
  18. }

  19. void draw() {
  20.   background(200);

  21.   pushMatrix();
  22.   translate(0, 0, -10);
  23.   fill(255);
  24.   rect(0, 0, 900, 600);
  25.   popMatrix();

  26.   ballX += speedX * dirX;
  27.   ballY += speedY * dirY;
  28.   fill(0);
  29.   ellipse(ballX, ballY, ballSize, ballSize);

  30.   if (ballX >= width || ballX <= 0)
  31.     dirX *= -1;

  32.   if (ballY >= height || ballY <= 0)
  33.     dirY *= -1;

  34.   println(frameRate);
  35. }

Re: Bad frameRate

1 year ago

use
Copy code
  1.   size(900, 600, OPENGL );
instead.

with
http://www.processing.org/reference/sphereDetail_.html
you can reduce the time to draw the sphere

smooth() slows things down

there's a technique to store fixed scenery (floor, walls...) in your graphic card - could be fast. Look it up here in the forum please.

Re: Bad frameRate

1 year ago



there's a technique to store fixed scenery (floor, walls...) in your graphic card - could be fast. Look it up here in the forum please.




I found this

http://forum.processing.org/topic/opengl-performance-tips


Re: Bad frameRate

1 year ago
Switching to OpenGL improved FPS insanely, thanks.