# How to pause part of a draw loop

**URL:** <https://discourse.processing.org/t/how-to-pause-part-of-a-draw-loop/36891>\
**Category:** Coding Questions\
**Created:** [May 15, 2022, 6:23am UTC](https://discourse.processing.org/t/how-to-pause-part-of-a-draw-loop/36891 "2022-05-15T06:23:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Blushdow7](https://avatars.discourse-cdn.com/v4/letter/b/c67d28/32.png) [@Blushdow7](https://discourse.processing.org/u/Blushdow7)\
**Post date:** [May 15, 2022, 6:23am UTC](https://discourse.processing.org/t/how-to-pause-part-of-a-draw-loop/36891/1 "2022-05-15T06:23:51Z")

</div>

I’m trying to make my character be able to crouch so i have

void draw ()  
background(0)

```
imageMode(CENTER);
image(box.image1,0,0);

```

void keyPressed()  
{  
if (key == ‘s’)  
{  
image(box.image3, box.position.x, box.position.y);  
}

it all works fine but the draw loop instantly replaces image 3 with image 1  
if i pause the whole of draw then it places it and it isnt immediately replaced but i can still see image1 in the background because its no longer doing the background every frame is ther ea way to pause part of draw?

---

<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:** [May 15, 2022, 7:37am UTC](https://discourse.processing.org/t/how-to-pause-part-of-a-draw-loop/36891/2 "2022-05-15T07:37:43Z")

</div>

Better way : in keyPressed set a boolean variable `crouch` to true

Define it as global (aka before setup())

in keyPressed say `crouch = true;`

Evaluate it in draw() and display one image **or** the other  
Use `if(crouch) image...; else image....;`

(keyPressed() is only called once, so no use to draw anything there. draw() runs 60 times per second)

Use keyReleased() to say `crouch = false;` then he crouches as long as you hold the key down.

---

<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:** [May 15, 2022, 10:50am UTC](https://discourse.processing.org/t/how-to-pause-part-of-a-draw-loop/36891/3 "2022-05-15T10:50:30Z")

</div>

**Remark**

When box is a class that you wrote it is better to write a function display() inside the function and just call the function. Then `crouch` variable wouldn’t be global but part of the class.

The if clause I described would be inside of display() function.

Much better readable.

**Example**

instead of

` image(box.image3, box.position.x, box.position.y);`

you would have inside the class

` image(image3, position.x, position.y);`

---

<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:** [May 15, 2022, 9:09pm UTC](https://discourse.processing.org/t/how-to-pause-part-of-a-draw-loop/36891/5 "2022-05-15T21:09:14Z")

</div>

> [@Blushdow7](#):
>
> else  
> {  
> image(box.image1, box.position.x, box.position.y);  
> }

Somehow behind this a } is missing…?

Please format your code
