# How to solve this fps problem?

**URL:** <https://discourse.processing.org/t/how-to-solve-this-fps-problem/37959>\
**Category:** Processing for Android\
**Created:** [July 15, 2022, 3:56am UTC](https://discourse.processing.org/t/how-to-solve-this-fps-problem/37959 "2022-07-15T03:56:18Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Coder1](https://avatars.discourse-cdn.com/v4/letter/c/d9b06d/32.png) [@Coder1](https://discourse.processing.org/u/Coder1)\
**Post date:** [July 15, 2022, 3:56am UTC](https://discourse.processing.org/t/how-to-solve-this-fps-problem/37959/1 "2022-07-15T03:56:18Z")

</div>

> please format code with \</\> button \* [homework policy](https://discourse.processing.org/faq/#homework) \* [asking questions](https://discourse.processing.org/t/2147)  
> Hello. I have been working on a game very well but after time my biggest issue became the bad fps in my game. I have tried using threads to somehow solve my problem. The fps issue is solved when I thread the refresh() function. But then everything is being moved weirdly and chaos happens on my screen. Then I tried running the refresh function without a thread. The chaos problem was solved but then the fps problem faces me again. Can someone please help me? I have no experience and knowledge using the gpu. Thank you very much

```auto
if (playing == true) {
      if (Pause == false) {
        println(frameRate);
        //thread("testLol");
        //image(hpBoss, xhpBoss, yhpBoss - height/4.5176, height/15.36, height/15.36); //hpBossIcon
        //image(hpPlayer, xhpPlayer, yhpPlayer - height/4.5176, height/15.36, height/15.36); //hpPlayerIcon
        //imageMode(CORNER);
        //rect(xHPIcon, yHPIcon - height/4.5176, bHPIcon, hHPIcon);
        //rectMode(CORNER);
        /*imageMode(CENTER);
         image(pfeilButtonLinks,height/9.6,height/1.11304,height/5.12,height/5.12);
         image(pfeilButtonRechts,height/3.072,height/1.11304,height/5.12,height/5.12);
         image(attackButton,height/0.60235,height/1.11304,height/5.12,height/5.12);
         image(blockButton,height/0.69818,height/1.11304,height/5.12,height/5.12);
         image(skill1Button,height/0.83027,height/1.11304,height/5.12,height/5.12);
         image(skill2Button,height/0.83027,height/1.44905,height/5.12,height/5.12);*/
        //imageMode(CORNER);
        //fill(0, 130, 0);
        //rect(xPlayerHP, yPlayerHP - height/4.5176, height/3.072, height/10.9714); //PlayerHP refresh
        //fill(0, 255, 0);
        //rect(xPlayerHP, yPlayerHP - height/4.5176, sPlayerHP, height/10.9714); //PlayerHP
        //rectMode(CORNER);
        //fill(0);
        //rect(width-height/4.11157, height/5.23684, height/4.145833, height/13.266666); //timer Refresh
        //fill(130, 0, 0);
        //rect(width-height/2.50177, height/1.1814999 - height/4.5176, height/3.076154, height/10.96769); //BossHP refresh
        //fill(255, 0, 0);
        //rectMode(CORNERS);
        //rect(xBossHP1, yBossHP1 - height/4.5176, xBossHP2, yBossHP2 - height/4.5176); //BossHP
        //rectMode(CENTER);
        thread("startCdTimerSun1");
        thread("startCdTimerSun2");
        thread("spielerBewegen");
        thread("bossBewegen");
        thread("aktiviereMoonFormen");
        thread("formenLinksRechts");
        thread("playerSlash");
        thread("playerBlocking");
        thread("defeat");
        thread("victory");
        thread("runThroughWall");
        thread("playerSlashCD");
        thread("loseHPTouching");
        //m.moonBreathing1stForm();
        //m.moonBreathing3rdForm();
        //p.playerAttack();
        thread("bossIsOnFire");
        //s.sunBreathing2ndForm();
        //sunBreathing();
        thread("timer");
        refresh();
      }
      pause();
      //1920x1080
    }

void refresh() {
  rectMode(CENTER);
  fill(0);
  rectMode(CENTER);
  rect(xBoss, yBoss, bSize+height/6.144, bSize); //refresh Boss
  rectMode(CENTER);
  rect(xPlayer, yPlayer, pSize + height/6.144, pSize); //Spieler refresh
  imageMode(CENTER);
  image(playerStay[load1TimeIMGp], xPlayer, yPlayer, pSize, pSize); //Spieler
  imageMode(CENTER);
  image(bossStay[load1TimeIMGb], xBoss, yBoss, bSize, bSize); //Boss
  imageMode(CENTER);
  image(hpBoss, xhpBoss, yhpBoss - height/4.5176, height/15.36, height/15.36); //hpBossIcon
  imageMode(CENTER);
  image(hpPlayer, xhpPlayer, yhpPlayer - height/4.5176, height/15.36, height/15.36); //hpPlayerIcon
  rectMode(CORNER);
  fill(0);
  rectMode(CORNER);
  rect(width-height/4.11157, height/5.23684, height/4.145833, height/13.266666); //timer Refresh
  imageMode(CORNER);
  image(cdZahlen[timerImages1], width - height/9.95, height/6.0472, height/7.68, height/7.68);
  imageMode(CORNER);
  image(cdZahlen[timerImages2], width - height/6.21875, height/6.0472, height/7.68, height/7.68);
  imageMode(CORNER);
  image(cdZahlen[timerImages3], width - height/3.82692, height/6.0472, height/7.68, height/7.68);
  imageMode(CORNER);
  image(doppelPunkt, width-height/4.975, height/5.527777, height/9.47619, height/9.95);
  fill(130, 0, 0);
  rect(width-height/2.50177, height/1.1814999 - height/4.5176, height/3.076154, height/10.96769); //BossHP refresh
  fill(0, 130, 0);
  rect(xPlayerHP, yPlayerHP - height/4.5176, height/3.072, height/10.9714); //PlayerHP refresh
  fill(0, 255, 0);
  rect(xPlayerHP, yPlayerHP - height/4.5176, sPlayerHP, height/10.9714); //PlayerHP
  rectMode(CORNERS);
  fill(255, 0, 0);
  rect(xBossHP1, yBossHP1 - height/4.5176, xBossHP2, yBossHP2 - height/4.5176); //BossHP
  imageMode(CORNER);
  rectMode(CORNER);
  fill(0);
  rect(height/2.4774, height/3.072, height/7.68, height/12.8);
  rect(height/2.4774, height/4.2666, height/7.68, height/12.8);
  image(cdZahlen[i1], height/3.0117, height/3.8984, height/7.68, height/7.68);
  image(cdZahlen[i2], height/3.0117, height/6.0472, height/7.68, height/7.68);
  image(skill1CD, height/76.8, height/3.6571, height/3.072, height/9.6);
  image(skill2CD, height/76.8, height/5.48571, height/3.072, height/9.6);
}

```

---

<div class="post-metadata">

**Author:** ![J\_Silva](https://avatars.discourse-cdn.com/v4/letter/j/3d9bf3/32.png) [@J\_Silva](https://discourse.processing.org/u/J_Silva)\
**Post date:** [July 15, 2022, 10:55am UTC](https://discourse.processing.org/t/how-to-solve-this-fps-problem/37959/2 "2022-07-15T10:55:40Z")

</div>

Hi. Maybe you could upload the whole code with images etc. to Drive or Github to see what’s going on.

---

<div class="post-metadata">

**Author:** ![Coder1](https://avatars.discourse-cdn.com/v4/letter/c/d9b06d/32.png) [@Coder1](https://discourse.processing.org/u/Coder1)\
**Post date:** [July 15, 2022, 11:21am UTC](https://discourse.processing.org/t/how-to-solve-this-fps-problem/37959/3 "2022-07-15T11:21:33Z")

</div>

Hi. Unfortunately I can’t do it on Github. If I upload the whole code then no one will understand anything because my code is all messed up. Everything that is being displayed on the screen is only written in my refresh() function

 ![Screenshot_20220715_131919_com.huawei.himovie.overseas](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/2/1/21630ea2dec3202dbd756eb3043dcb987f01f04b.jpeg)

Here is an image of my problem.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [July 15, 2022, 1:09pm UTC](https://discourse.processing.org/t/how-to-solve-this-fps-problem/37959/4 "2022-07-15T13:09:02Z")

</div>

a few things

- what is pause() doin’?
- never use image() with 5 parameters. Instead resize() it in setup() once and for all and then use image() with 3 parameters
- thread is not supposed to be started throughout! Only once in setup()

---

<div class="post-metadata">

**Author:** ![Coder1](https://avatars.discourse-cdn.com/v4/letter/c/d9b06d/32.png) [@Coder1](https://discourse.processing.org/u/Coder1)\
**Post date:** [July 15, 2022, 4:29pm UTC](https://discourse.processing.org/t/how-to-solve-this-fps-problem/37959/5 "2022-07-15T16:29:43Z")

</div>

I commented pause out because it is a work in progress. Is it bad using image() with 5 parameters? Why?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [July 15, 2022, 4:45pm UTC](https://discourse.processing.org/t/how-to-solve-this-fps-problem/37959/6 "2022-07-15T16:45:49Z")

</div>

pause() sounds bad; it sounds like delay

5 parameters let processing resize the image which is very time consuming; and it does so not once but every time, 60 times per second

But the thread() thing is even worse imho

---

<div class="post-metadata">

**Author:** ![Coder1](https://avatars.discourse-cdn.com/v4/letter/c/d9b06d/32.png) [@Coder1](https://discourse.processing.org/u/Coder1)\
**Post date:** [July 15, 2022, 5:04pm UTC](https://discourse.processing.org/t/how-to-solve-this-fps-problem/37959/7 "2022-07-15T17:04:56Z")

</div>

I changed the code before. I removed all threads. I use images with different size so scaling them in setup wont do much I guess. Is it really a big difference to use 3 parameters instead of 5? When I use images with different height then I guess I will have to scale them differently anyway

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [July 15, 2022, 5:26pm UTC](https://discourse.processing.org/t/how-to-solve-this-fps-problem/37959/8 "2022-07-15T17:26:49Z")

</div>

> [@Coder1](#):
>
> I use images with different size so scaling them in setup wont do much

I don’t agree. You can scale them individually in setup(). Or do you mean one image changes its size during the game?

> [@Coder1](#):
>
> Is it really a big difference to use 3 parameters instead of 5?

Yes, it is.

But test it yourself, when it’s fast enough for you, good. I am happy to drop my point.

---

<div class="post-metadata">

**Author:** ![Coder1](https://avatars.discourse-cdn.com/v4/letter/c/d9b06d/32.png) [@Coder1](https://discourse.processing.org/u/Coder1)\
**Post date:** [July 15, 2022, 5:28pm UTC](https://discourse.processing.org/t/how-to-solve-this-fps-problem/37959/9 "2022-07-15T17:28:31Z")

</div>

Oh ok thank you I will try it
