# \[CLOSED\] Images appearing while using rect()

**URL:** <https://discourse.processing.org/t/closed-images-appearing-while-using-rect/11517>\
**Category:** Coding Questions\
**Created:** [May 23, 2019, 3:03pm UTC](https://discourse.processing.org/t/closed-images-appearing-while-using-rect/11517 "2019-05-23T15:03:13Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![YDGames](https://avatars.discourse-cdn.com/v4/letter/y/a8b319/32.png) [@YDGames](https://discourse.processing.org/u/YDGames)\
**Post date:** [May 23, 2019, 3:03pm UTC](https://discourse.processing.org/t/closed-images-appearing-while-using-rect/11517/1 "2019-05-23T15:03:14Z")

</div>

In my game there are enemies wandering around, their draw() method is simple:

```auto
        if(facingRight) {
            core.displayBuffer.image(image,
                    x, y + offsetY, 80, 80);
        } else {
            float tX = -core.camera.x+core.game.width/2f + x;
            float tY = -core.camera.y+core.game.height/2f+ y;
            
            core.displayBuffer.pushMatrix();
    
            core.displayBuffer.translate(core.camera.x-core.game.width/2f,
                    core.camera.y-core.game.height/2f);
            core.displayBuffer.translate(tX, tY);
            core.displayBuffer.scale(-1, 1);
            
            core.displayBuffer.image(image,
                    -80, offsetY, 80, 80);
            
            core.displayBuffer.popMatrix();
        }

```

Then when we are going to draw walls, we just draw a coloured rectangle like this:

```
    core.displayBuffer.noStroke();

    if(destroyed) {
        core.displayBuffer.fill(0, 0, 0, 16);
        core.displayBuffer.rect(x, y, w, h);
    } else {
        core.displayBuffer.fill(64);
        core.displayBuffer.rect(x, y - WALL_HEIGHT, w, h);
        core.displayBuffer.fill(32);
        core.displayBuffer.rect(x, y + h - WALL_HEIGHT, w, WALL_HEIGHT);
    }

```

But for some reason, the walls have the texture of the enemies? Here’s the loop in which the objects are drawn:

```
    PMatrix displayMatrix = displayBuffer.getMatrix();
    PMatrix bloomMatrix = bloomLayer.getMatrix();
    PStyle displayStyle = displayBuffer.getStyle();
    PStyle bloomStyle = bloomLayer.getStyle();
    
    onScreenObjects.forEach(o -> {
        displayBuffer.setMatrix(displayMatrix);
        bloomLayer.setMatrix(bloomMatrix);
        displayBuffer.style(displayStyle);
        bloomLayer.style(bloomStyle);
        o.draw(this);
    });
    
    displayBuffer.setMatrix(displayMatrix);
    bloomLayer.setMatrix(bloomMatrix);
    displayBuffer.style(displayStyle);
    bloomLayer.style(bloomStyle);

```

Here’s example of the results, red rectangles are around the walls, that are drawn incorrectly.  
Also the bullets are flickering for some reason? These 2 bugs don’t appear when I don’t draw the enemies onto the screen (or I draw just rectangles instead), so that means, that the image() is doing something weird in the background?

 ![bug](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/b/bd961c9588f9be793fd843cb8430a1caeed29c62.png)

Ask for additional info if needed!

* * *

Nvidia Quadro 4000.  
Graphics card driver is from 2016, can’t upgrade it, all other games are working fine tho.

---

<div class="post-metadata">

**Author:** ![cdr6934](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/cdr6934/32/12269_2.png) [@cdr6934](https://discourse.processing.org/u/cdr6934)\
**Post date:** [May 23, 2019, 4:41pm UTC](https://discourse.processing.org/t/closed-images-appearing-while-using-rect/11517/2 "2019-05-23T16:41:36Z")

</div>

> [@YDGames](#):
>
> core.displayBuffer.fill(0, 0, 0, 16);

Not sure if this is could be your issue but I’d bet it has something to do with the alpha channel at some point when redrawing your screen.

---

<div class="post-metadata">

**Author:** ![InferNova](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/infernova/32/6009_2.png) [@InferNova](https://discourse.processing.org/u/InferNova)\
**Post date:** [May 23, 2019, 4:52pm UTC](https://discourse.processing.org/t/closed-images-appearing-while-using-rect/11517/3 "2019-05-23T16:52:58Z")

</div>

Hey there!  
Could you provide sprites / a dumb down version so we can try it ourselves ? 😃

---

<div class="post-metadata">

**Author:** ![YDGames](https://avatars.discourse-cdn.com/v4/letter/y/a8b319/32.png) [@YDGames](https://discourse.processing.org/u/YDGames)\
**Post date:** [May 23, 2019, 4:53pm UTC](https://discourse.processing.org/t/closed-images-appearing-while-using-rect/11517/4 "2019-05-23T16:53:29Z")

</div>

Take a look at the drawing loop (the third long code section). The PStyle gets reset before and after every object so when clearing the screen, the alpha doesn’t matter. The alpha only manipulates the alpha of the wall.

I’m clearing the buffers with .clear() so the alpha matter actually doesn’t matter at all.

---

<div class="post-metadata">

**Author:** ![YDGames](https://avatars.discourse-cdn.com/v4/letter/y/a8b319/32.png) [@YDGames](https://discourse.processing.org/u/YDGames)\
**Post date:** [May 23, 2019, 4:54pm UTC](https://discourse.processing.org/t/closed-images-appearing-while-using-rect/11517/5 "2019-05-23T16:54:22Z")

</div>

It will take some times to reproduce it, because the project is like 15k lines of code… But I will try my best, I will post the code here soon.

---

<div class="post-metadata">

**Author:** ![InferNova](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/infernova/32/6009_2.png) [@InferNova](https://discourse.processing.org/u/InferNova)\
**Post date:** [May 23, 2019, 4:55pm UTC](https://discourse.processing.org/t/closed-images-appearing-while-using-rect/11517/6 "2019-05-23T16:55:51Z")

</div>

Oh wow ! How about just give us the code with the Sprite ? Aka Just the part which is causing the bugs ?

---

<div class="post-metadata">

**Author:** ![YDGames](https://avatars.discourse-cdn.com/v4/letter/y/a8b319/32.png) [@YDGames](https://discourse.processing.org/u/YDGames)\
**Post date:** [May 23, 2019, 5:00pm UTC](https://discourse.processing.org/t/closed-images-appearing-while-using-rect/11517/7 "2019-05-23T17:00:05Z")

</div>

I will take the whole project and just delete away everything that doesn’t matter, it will not be very small but the problem is… I don’t know where the bug actually is, because there are some post-processing effects and so on.

I will be done in 10 mins I guess…

---

<div class="post-metadata">

**Author:** ![InferNova](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/infernova/32/6009_2.png) [@InferNova](https://discourse.processing.org/u/InferNova)\
**Post date:** [May 23, 2019, 5:01pm UTC](https://discourse.processing.org/t/closed-images-appearing-while-using-rect/11517/8 "2019-05-23T17:01:02Z")

</div>

Oh so maybe you should try then locate the bug first ! Did you try stepping with a debugger on potential areas or disabling certain parts to the see doesn’t change anything?

---

<div class="post-metadata">

**Author:** ![YDGames](https://avatars.discourse-cdn.com/v4/letter/y/a8b319/32.png) [@YDGames](https://discourse.processing.org/u/YDGames)\
**Post date:** [May 23, 2019, 5:05pm UTC](https://discourse.processing.org/t/closed-images-appearing-while-using-rect/11517/9 "2019-05-23T17:05:00Z")

</div>

I have tried many things, all post-processing effects are disabled and I have eliminated some stuff more, as you see there are only walls and enemies on the screen.

The only thing that I have found is not drawing enemies fixes the problem 😂

---

<div class="post-metadata">

**Author:** ![YDGames](https://avatars.discourse-cdn.com/v4/letter/y/a8b319/32.png) [@YDGames](https://discourse.processing.org/u/YDGames)\
**Post date:** [May 23, 2019, 5:41pm UTC](https://discourse.processing.org/t/closed-images-appearing-while-using-rect/11517/10 "2019-05-23T17:41:45Z")

</div>

Still haven’t succeeded to reproduce it… I have no idea what causes it, I will try my game on another computer tomorrow, I have to go to sleep soon.

---

<div class="post-metadata">

**Author:** ![InferNova](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/infernova/32/6009_2.png) [@InferNova](https://discourse.processing.org/u/InferNova)\
**Post date:** [May 23, 2019, 6:01pm UTC](https://discourse.processing.org/t/closed-images-appearing-while-using-rect/11517/11 "2019-05-23T18:01:17Z")

</div>

Can you make the whole source code available in a github or something ? I be very excited to help !

---

<div class="post-metadata">

**Author:** ![YDGames](https://avatars.discourse-cdn.com/v4/letter/y/a8b319/32.png) [@YDGames](https://discourse.processing.org/u/YDGames)\
**Post date:** [May 24, 2019, 7:26am UTC](https://discourse.processing.org/t/closed-images-appearing-while-using-rect/11517/12 "2019-05-24T07:26:18Z")

</div>

I will need to upload the entire project to github anyways, why not make it public then (temporarly). I will be home in 30 mins or more.

---

<div class="post-metadata">

**Author:** ![YDGames](https://avatars.discourse-cdn.com/v4/letter/y/a8b319/32.png) [@YDGames](https://discourse.processing.org/u/YDGames)\
**Post date:** [May 24, 2019, 8:22am UTC](https://discourse.processing.org/t/closed-images-appearing-while-using-rect/11517/13 "2019-05-24T08:22:31Z")

</div>

Here’s the repository for the project, read the readme.md and it will tell you what to import and how to get it up and running. I’m using IntelliJ but you can use any Java IDE you want (that suits the job).

---

<div class="post-metadata">

**Author:** ![YDGames](https://avatars.discourse-cdn.com/v4/letter/y/a8b319/32.png) [@YDGames](https://discourse.processing.org/u/YDGames)\
**Post date:** [May 24, 2019, 12:47pm UTC](https://discourse.processing.org/t/closed-images-appearing-while-using-rect/11517/14 "2019-05-24T12:47:44Z")

</div>

I solved the problem… by accident, I was just rewriting some code and it was gone later when I tested it. I had a translate() that was shifting the view always but it got reset after every frame so I couldn’t see it happening, instead I saw weird glitch that seemed like images were drawn with rect(). I’m not quite sure if that was the solution, maybe there’s something hiding it, but if I see it happening again, I will repost here or make a new thread.

---

<div class="post-metadata">

**Author:** ![InferNova](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/infernova/32/6009_2.png) [@InferNova](https://discourse.processing.org/u/InferNova)\
**Post date:** [May 24, 2019, 1:57pm UTC](https://discourse.processing.org/t/closed-images-appearing-while-using-rect/11517/15 "2019-05-24T13:57:08Z")

</div>

Great! Good luck with the project looks great from the picture !

---

<div class="post-metadata">

**Author:** ![YDGames](https://avatars.discourse-cdn.com/v4/letter/y/a8b319/32.png) [@YDGames](https://discourse.processing.org/u/YDGames)\
**Post date:** [May 25, 2019, 12:03pm UTC](https://discourse.processing.org/t/closed-images-appearing-while-using-rect/11517/16 "2019-05-25T12:03:08Z")

</div>

The bug is back… Let’s get back to work 😃. I will update the GitHub repository and I will tell what I did for the bug to appear.

---

<div class="post-metadata">

**Author:** ![YDGames](https://avatars.discourse-cdn.com/v4/letter/y/a8b319/32.png) [@YDGames](https://discourse.processing.org/u/YDGames)\
**Post date:** [May 25, 2019, 12:34pm UTC](https://discourse.processing.org/t/closed-images-appearing-while-using-rect/11517/17 "2019-05-25T12:34:47Z")

</div>

My GitHub repository: [https://github.com/Matrx007/TheLostBits](https://github.com/Matrx007/TheLostBits). It didn’t show up last time when I included it in my reply.

---

<div class="post-metadata">

**Author:** ![InferNova](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/infernova/32/6009_2.png) [@InferNova](https://discourse.processing.org/u/InferNova)\
**Post date:** [May 25, 2019, 5:24pm UTC](https://discourse.processing.org/t/closed-images-appearing-while-using-rect/11517/18 "2019-05-25T17:24:36Z")

</div>

Hooray! I was excited to see what this little beast of a game is ! I will have a look at it and let you know what I find.

---

<div class="post-metadata">

**Author:** ![YDGames](https://avatars.discourse-cdn.com/v4/letter/y/a8b319/32.png) [@YDGames](https://discourse.processing.org/u/YDGames)\
**Post date:** [May 27, 2019, 5:48am UTC](https://discourse.processing.org/t/closed-images-appearing-while-using-rect/11517/19 "2019-05-27T05:48:35Z")

</div>

Have you found anything? Did you saw the bug? I’m out of ideas…

---

<div class="post-metadata">

**Author:** ![YDGames](https://avatars.discourse-cdn.com/v4/letter/y/a8b319/32.png) [@YDGames](https://discourse.processing.org/u/YDGames)\
**Post date:** [May 28, 2019, 6:00am UTC](https://discourse.processing.org/t/closed-images-appearing-while-using-rect/11517/20 "2019-05-28T06:00:54Z")

</div>

!!! PROBLEM SOLVED !!!

Solution: [https://github.com/processing/processing/issues/5863](https://github.com/processing/processing/issues/5863)

My GitHub repo will now be made private!
