# Text wont draw in setup()

**URL:** https://discourse.processing.org/t/text-wont-draw-in-setup/41359
**Category:** Libraries
**Created:** [March 20, 2023, 9:30am UTC](https://discourse.processing.org/t/text-wont-draw-in-setup/41359 "2023-03-20T09:30:08Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![starzorrow](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/starzorrow/32/18135_2.png) [@starzorrow](https://discourse.processing.org/u/starzorrow)
#### Post date: [March 20, 2023, 9:30am UTC](https://discourse.processing.org/t/text-wont-draw-in-setup/41359/1 "2023-03-20T09:30:08Z")

</div>

okay so i have this code and im trying to draw text() in setup() right before i load and play a sound file. the problem is, the text does not draw until after the sound has loaded. if the sound code is commented out, the text loads fine.

```auto
void setup(){ 
  size(1100,800);
  background(20,20,20);
  noStroke();

  //Tri-force
  fill(255,255,0);
  triangle(420, 400, 532, 180, 644, 400);
  triangle(308, 620, 420, 400, 532, 620);
  triangle(532, 620, 644, 400, 756, 620);

  //Loading
  fill(255,255,255,trans-80);
  circle(1050,750,20);
  fill(255,255,255,trans-60);
  circle(1000,750,20);
  fill(255,255,255,trans-40);
  circle(950,750,20);
  text("This is a loading screen!", 50, 20); // this is the text

  file = new SoundFile(this,"PrincessZelda.mp3");
  file.play();

  //Volume meter(0-1)
  file.amp(.5);

}

```

im not sure what im doing wrong or why the text refuses to draw

this is probably in the wrong category but i didn’t know where else to put it. sorry

---

<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: [March 20, 2023, 9:47am UTC](https://discourse.processing.org/t/text-wont-draw-in-setup/41359/2 "2023-03-20T09:47:16Z")

</div>

Yeah, the screen is not updated throughout but just at the end of the function setup ().

You can move this into draw() :

file = new SoundFile(this,“PrincessZelda.mp3”);  
file.play();

//Volume meter(0-1)  
file.amp(.5);

And surround it with an if clause so it runs only once:

if(firstTime) {

…  
firstTime=false;  
}

Before setup you say

boolean firstTime=true;

---

<div class="post-metadata">

### Author: ![starzorrow](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/starzorrow/32/18135_2.png) [@starzorrow](https://discourse.processing.org/u/starzorrow)
#### Post date: [March 20, 2023, 10:31am UTC](https://discourse.processing.org/t/text-wont-draw-in-setup/41359/3 "2023-03-20T10:31:43Z")

</div>

Im pretty sure I tried this but the sound didn’t end up playing, but i’ll try again and I’ll update you!

Also just to note, everything but the text draws so that’s why im confused

---

<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: [March 20, 2023, 10:59am UTC](https://discourse.processing.org/t/text-wont-draw-in-setup/41359/4 "2023-03-20T10:59:34Z")

</div>

Hello @starzorrow ,

Here is an example that loads the sound file in the background and sets boolean flags for decisions on program flow/control:

```auto
//https://www.youtube.com/watch?v=P-KjGrbuov4

import processing.sound.*;

SoundFile file;

boolean loaded = false;
boolean done = false;

void setup()
  { 
  size(300, 300);
  textSize(48); 
  textAlign(CENTER, CENTER);
  thread("loadFile");
  }
  
void draw()
  {
  background(255, 0, 0);
  
  if(loaded == true)
    {
    file.play();
  
    //Volume meter(0-1)
    file.amp(1);
    loaded = false;
    done = true;
    } 

  if(done == false) 
    {
    fill(255);
    textSize(48);  
    text(frameCount, width/2, height/2-10);
    return; // jumps to end of draw() function
    }
    
    // Resume draw() cycle...
  
    background(0, 255, 0); 
    fill(0);
    text(frameCount, width/2, height/2-10);
    }
  
  void loadFile() 
    {
    file = new SoundFile(this, "Loituma - Ievas polka Ievan Polkka good sound.mp3");
    loaded = true;
    }

```

Please looks up all references to code here:

> **[Welcome to Processing!](https://processing.org/)**
>
> Processing is a flexible software sketchbook and a language for learning how to code. Since 2001, Processing has promoted software literacy within the visual arts and visual literacy within technology…

The _draw()_ reference states:

> All Processing programs update the screen at the end of draw(), never earlier.

This also applies to _setup()_ as well which is _frameCount = 0_;

When testing your code I had to add a _fill(255)_ for the text otherwise I did not see the text on the black background.

`:)`

---

<div class="post-metadata">

### Author: ![starzorrow](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/starzorrow/32/18135_2.png) [@starzorrow](https://discourse.processing.org/u/starzorrow)
#### Post date: [March 20, 2023, 12:14pm UTC](https://discourse.processing.org/t/text-wont-draw-in-setup/41359/5 "2023-03-20T12:14:15Z")

</div>

Okay so I tried it, the text now shows up, but the sound never loads. the program suspends because of the thread()

---

<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: [March 20, 2023, 2:27pm UTC](https://discourse.processing.org/t/text-wont-draw-in-setup/41359/6 "2023-03-20T14:27:31Z")

</div>

> [@glv](#):
>
> When testing your code I had to add a _fill(255)_ for the text otherwise I did not see the text on the black background.

That was the issue in the initial code

---

<div class="post-metadata">

### Author: ![starzorrow](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/starzorrow/32/18135_2.png) [@starzorrow](https://discourse.processing.org/u/starzorrow)
#### Post date: [March 20, 2023, 2:55pm UTC](https://discourse.processing.org/t/text-wont-draw-in-setup/41359/7 "2023-03-20T14:55:53Z")

</div>

```auto
	fill(255);
	textSize(30);
	text("This is the loading screen!", 20, 20);

	//music
	file = new SoundFile(this,"PrincessZelda.mp3");
	file.play();

	//Volume meter(0-1)
	file.amp(.5);

```

with the fill(255), the text appears to still not show while everything else does)
