# Using high FPS and Anti-Lag

**URL:** <https://discourse.processing.org/t/using-high-fps-and-anti-lag/44860>\
**Category:** Coding Questions\
**Created:** [July 29, 2024, 10:07pm UTC](https://discourse.processing.org/t/using-high-fps-and-anti-lag/44860 "2024-07-29T22:07:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![winterchan](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/winterchan/32/19921_2.png) [@winterchan](https://discourse.processing.org/u/winterchan)\
**Post date:** [July 29, 2024, 10:07pm UTC](https://discourse.processing.org/t/using-high-fps-and-anti-lag/44860/1 "2024-07-29T22:07:15Z")

</div>

Hi guys, im developing a game that involves spawning a large amount of entities at once, my default fps is 60, but when i use more fps it seems as if the game were to move faster, is that something common in processing ? and is there a way make it not happen while still maintaining a high fps?

Second thing is that my fps gradually drops from 60 to around 30-25 when the game reaches it entity spawn peak (at the end game), i was told there might be some ways to be able to spawn a lot of entities but somehow get much less lag , i would like to learn more about how to this, thanks in advanced!

Btw my code is thousands of lines so i can’t share all of it at this point but if needed i can share the parts that are relevant, i didn’t upload any because i figured the question is general and can be answered without the code.

---

<div class="post-metadata">

**Author:** ![scudly](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/scudly/32/5597_2.png) [@scudly](https://discourse.processing.org/u/scudly)\
**Post date:** [July 30, 2024, 1:52am UTC](https://discourse.processing.org/t/using-high-fps-and-anti-lag/44860/2 "2024-07-30T01:52:33Z")

</div>

For consistent motion independent of the frame rate, base your motion on the real world time. Get the `millis()` each frame and subtract from the previous frame to find the change in time (delta time or ‘`dt`’) then move your objects at `speed * dt`.

If you have a large amount of work to do, break it into smaller chunks and do a little bit each frame. If the player is entering a room with hundreds of enemies, create them gradually as the player approaches rather than the instant they enter the room. Alternatively use a separate compute thread to create the enemies, but that brings its own set of complexities to synchronize with the rendering thread.

---

<div class="post-metadata">

**Author:** ![sableraph](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sableraph/32/251_2.png) [@sableraph](https://discourse.processing.org/u/sableraph)\
**Post date:** [July 30, 2024, 8:39am UTC](https://discourse.processing.org/t/using-high-fps-and-anti-lag/44860/3 "2024-07-30T08:39:55Z")

</div>

Adding to @scudly’s point about deltaTime, I found this video by Jonas Tyroller  
particularly enlightening. Though it is not specifically about Processing, the concepts explained apply broadly to any game which deals with time and movement.

[![](https://img.youtube.com/vi/yGhfUcPjXuE/maxresdefault.jpg "Dear Game Developers, Stop Messing This Up!") ](https://www.youtube.com/watch?v=yGhfUcPjXuE&t=676s)

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [July 30, 2024, 9:35am UTC](https://discourse.processing.org/t/using-high-fps-and-anti-lag/44860/4 "2024-07-30T09:35:24Z")

</div>

You might find this blog [post](http://lagers.org.uk/blog/?p=63) helpful (or interesting if not helpful 😄) as it is directly related to Processing.

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [August 5, 2024, 3:51pm UTC](https://discourse.processing.org/t/using-high-fps-and-anti-lag/44860/5 "2024-08-05T15:51:41Z")

</div>

> [@winterchan](#):
>
> that my fps gradually drops from 60 to around 30-25 when the game reaches it entity spawn peak (at the end game), i was told there might be some ways to be able to spawn a lot of entities but somehow get much less lag , i would like to learn more about how to this, thanks in advanced!

An example I have comparing points and circles with different renderers:

```auto
import processing.javafx.*; // You have to add this library!

int dia = 100;
boolean toggle;

void setup()
  {
  size(800, 800);
  //size(800, 800, P2D);
  //size(800, 800, P3D);
  //size(800, 800, FX2D);
  
  background(0);
  }
  
int t0, t1, td;  
String txt;  
  
void draw()
  {
  background(0);
  
  surface.setTitle(str(frameRate));
  
  if (toggle)
    {
    txt = "point";
    t0 = millis();
    strokeWeight(3);
    stroke(255);
    for(int i=0; i<10000; i++)
      {
      //stroke(random(256));
      stroke(128*randomGaussian()+128);
      point(random(width), random(height));
      }
    t1 = millis();  
    }
  else
    {
    txt = "circle";  
    t0 = millis();  
    noStroke();
    fill(255);
    for(int i=0; i<10000; i++)
      {
      fill(128*randomGaussian()+128);  
      circle(random(width), random(height), 3);
      }
    t1 = millis();  
    }
  
  println(txt, t1-t0);
  }
  
void keyPressed() // Select between points and circle
  {
  toggle = !toggle;
  }

```

References:

- [Render Techniques / Processing.org](https://processing.org/tutorials/rendering)
- [size() / Reference / Processing.org](https://processing.org/reference/size_.html)
- [Faster Rendering Techniques in P3D?](https://discourse.processing.org/t/faster-rendering-techniques-in-p3d/31465)

`:)`
