Introduction
This is a common thing that happens when you are making a GUI program.
Today, i will show you how to fix this effect.
This is a method i found that uses the Window (API)
- Window API
- This is why you should use Computercraft 1.6 or higher
How it works
This is very easy to understand.
First, we make a Window that is the same size as the monitor.
Then at the beginning of rendering, we will redirect to the window.
Then at the end, we will redirect back to the main terminal and we will show the window.
The code
Here we have an example code:
function render() paintutils.drawFilledBox(5, 5, 30, 16, colors.green) paintutils.drawFilledBox(5, 5, 30, 16, colors.red) paintutils.drawFilledBox(5, 5, 30, 16, colors.blue) paintutils.drawFilledBox(5, 5, 30, 16, colors.black) paintutils.drawFilledBox(5, 5, 30, 16, colors.blue) paintutils.drawFilledBox(5, 5, 30, 16, colors.white) paintutils.drawFilledBox(5, 5, 30, 16, colors.lightBlue) end while true do os.pullEvent() render() endIf you trigger an event (for example pressing a key).
The rectangles wil start to draw and you can see the flickering effect.
To fix this, we will first add a "getSize" function at the begin of the code. This is needed to give the window the size of the monitor.
I added the "term.current" function to redirect back to the main terminal.
local w, h = term.getSize() local currTerm = term.current()
After that, we will make the window:
local window = window.create(currTerm, 1, 1, w, h, false)
Then at the beginning of the render function, we will add this:
This is to redirect to the window (This means if we draw something now on the screen. It will be drawn in the window)
term.redirect(window)
At the end of the render function, we will add this:
This is to redirect back to the main terminal (If we draw something now. It will be drawn normally) and
to show and hide the window.
term.redirect(currTerm) window.setVisible(true) window.setVisible(false)
You will end up like this:
local w, h = term.getSize() local currTerm = term.current() local window = window.create(currTerm, 1, 1, w, h, false) function render() term.redirect(window) paintutils.drawFilledBox(5, 5, 30, 16, colors.green) paintutils.drawFilledBox(5, 5, 30, 16, colors.red) paintutils.drawFilledBox(5, 5, 30, 16, colors.blue) paintutils.drawFilledBox(5, 5, 30, 16, colors.black) paintutils.drawFilledBox(5, 5, 30, 16, colors.blue) paintutils.drawFilledBox(5, 5, 30, 16, colors.white) paintutils.drawFilledBox(5, 5, 30, 16, colors.lightBlue) term.redirect(currTerm) window.setVisible(true) window.setVisible(false) end while true do os.pullEvent() render() end
If you now test it out.
It would normally work.
If you are having problems.
You can post everything in the comment section below.
That is it for the fix.
Edited by IliasHDZ, 01 August 2018 - 09:56 AM.











