# Very low FPS problem

**URL:** <https://discourse.processing.org/t/very-low-fps-problem/13533>\
**Category:** Coding Questions\
**Created:** [August 21, 2019, 9:23pm UTC](https://discourse.processing.org/t/very-low-fps-problem/13533 "2019-08-21T21:23:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raiben23](https://avatars.discourse-cdn.com/v4/letter/r/f19dbf/32.png) [@Raiben23](https://discourse.processing.org/u/Raiben23)\
**Post date:** [August 21, 2019, 9:23pm UTC](https://discourse.processing.org/t/very-low-fps-problem/13533/1 "2019-08-21T21:23:55Z")

</div>

Hi,  
I’m having a problem with a code that I’m testing, that’s:

```auto

Star[] s;
Nave n;
Asteroide[] ast;
Planets[] plan;
int numast = 5;
int numplan = 2;
int numstar = 500; 
void setup() {
  size(1200, 600);
 // frameRate(1000);
  
  s = new Star[numstar];
  ast = new Asteroide[numast];
  plan = new Planets[numplan]; // Create the array
  n = new Nave();
  
  for (int i = 0; i < ast.length; i++) {
    ast[i] = new Asteroide();
  }
  for (int i = 0; i < s.length; i++) {
    s[i] = new Star();
  }
  for (int i = 0; i < plan.length; i++) {
    plan[i] = new Planets();
  }
}

void draw() {
  
  background(0);
  n.Mostrar();
  n.keyPressed();
  for (int i = 0; i < ast.length; i++) {
    ast[i].Mostrar();
     ast[i].Animar();
  }
  for (int i = 0; i < s.length; i++) {
    s[i].dibujar();
    s[i].Animar();
  }
  for (int i = 0; i < plan.length; i++) {
    plan[i].Mostrar();
    plan[i].Animar();
  }
  text(frameRate, 50, 50);
}

```

the plan, ast, and s arrays contains random images from data. I have tried changing size() with the resolution, and FX2D, P2D…etc I only get 2-4 FPS!!!

I would be grateful if anyone knows how to fix it

PD:Sorry for my english…

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [August 21, 2019, 10:17pm UTC](https://discourse.processing.org/t/very-low-fps-problem/13533/2 "2019-08-21T22:17:38Z")

</div>

you not mention what hardware your sketch run on?  
507 images 3 times per second sounds only bad if you want 1000 times per second.

---

<div class="post-metadata">

**Author:** ![Raiben23](https://avatars.discourse-cdn.com/v4/letter/r/f19dbf/32.png) [@Raiben23](https://discourse.processing.org/u/Raiben23)\
**Post date:** [August 21, 2019, 10:26pm UTC](https://discourse.processing.org/t/very-low-fps-problem/13533/3 "2019-08-21T22:26:14Z")

</div>

star is ellipse that have 5 pix of radius, btw i think that the hardware is not the problem , first, because I’m using i7 with GTX1060 graphic card, second, because it’s very very simple code… :

 ![Captura](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/d/dd86e41adc901ad4093d01ebb2ce2f96a8d3a2bc.jpeg)

it’s an attempt of the Asteroid game 😄

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [August 22, 2019, 12:06am UTC](https://discourse.processing.org/t/very-low-fps-problem/13533/4 "2019-08-22T00:06:20Z")

</div>

so the 500 stars are what, if not a image, a shape? created and drawn at draw, created at setup…  
also the images, how big are they, how you load them, how you draw them… there are many possible problems.

so, possibly if you show the full code and might even add the image files,  
there is a chance to find something, like that you try to resize the images with

```auto
image(img,x,y,w,h); 

```

8 \* 1000 / per sec ( if the stars are no images )

anyhow i expect that you get your own feeling where the problem is,  
by testing ( recording FPS ) influence of

- canvas size
- number of stars
- number of planets
- number of asteroids
- no spaceship

---

<div class="post-metadata">

**Author:** ![Raiben23](https://avatars.discourse-cdn.com/v4/letter/r/f19dbf/32.png) [@Raiben23](https://discourse.processing.org/u/Raiben23)\
**Post date:** [August 22, 2019, 5:13pm UTC](https://discourse.processing.org/t/very-low-fps-problem/13533/5 "2019-08-22T17:13:25Z")

</div>

> **[raiben23/Asteroid](https://github.com/raiben23/Asteroid)**
>
> Code example of Asteroid game. Contribute to raiben23/Asteroid development by creating an account on GitHub.

Maybe something, I’m not doing well when loading the images

---

<div class="post-metadata">

**Author:** ![Raiben23](https://avatars.discourse-cdn.com/v4/letter/r/f19dbf/32.png) [@Raiben23](https://discourse.processing.org/u/Raiben23)\
**Post date:** [August 22, 2019, 7:57pm UTC](https://discourse.processing.org/t/very-low-fps-problem/13533/6 "2019-08-22T19:57:12Z")

</div>

Already, the problem was that in the way that my code is structured, the images were loaded in each iteration of the loop, I have done some functions separately and it has been solved, anyway thank you very much for the help, I leave this here in case someone has the same problem
