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?
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.
- float ballX, ballY;
- float speedX = 7;
- float speedY = 5;
- int dirX = 1;
- int dirY = 1;
- void setup() {
- size(900, 600, P3D);
- background(200);
- smooth();
- noFill();
- //noStroke();
- //noCursor();
- camera(
- width/2.0, 600, 500,
- width/2.0, height/2, -200,
- 0, 1, 0);
- ballX = width/2;
- ballY = height/2;
- }
- void draw() {
- background(200);
- //Creates floor
- fill(255);
- rect(0, 0, 900, 600);
- //Creates top wall
- pushMatrix();
- translate(width/2, -100/2, 50/2);
- fill(150);
- box(width + 400, 100, 50);
- popMatrix();
- //Creates sphere
- ballX += speedX * dirX;
- ballY += speedY * dirY;
- pushMatrix();
- translate(ballX, ballY, 6);
- fill(50);
- sphere(6);
- popMatrix();
- //Creates paddle 1
- pushMatrix();
- translate(60, mouseY, 15/2+5);
- fill(255, 0, 0);
- box(15, 60, 15);
- popMatrix();
- //Creates paddle 2
- pushMatrix();
- translate(width - 60, mouseY, 15/2+5);
- fill(0, 0, 255);
- box(15, 60, 15);
- popMatrix();
- if (ballX >= width || ballX <= 0)
- dirX *= -1;
- if (ballY >= height || ballY <= 0)
- dirY *= -1;
- println(frameRate);
- }
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.
1