Very low FPS problem

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

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() {
  for (int i = 0; i < ast.length; i++) {
  for (int i = 0; i < s.length; i++) {
  for (int i = 0; i < plan.length; i++) {
  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…

1 Like

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.

1 Like

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… :

it’s an attempt of the Asteroid game :smile:

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


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

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

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