How can i get my code not to flacker?;D
Author |
Message |
munt4life
|
Posted: Sun Dec 26, 2010 2:51 pm Post subject: How can i get my code not to flacker?;D |
|
|
var x, y : int
var top, bottom, left, right : boolean := false
x := 100
y := 100
var chars : array char of boolean
loop
Input.KeyDown (chars)
if chars (KEY_UP_ARROW) and (y < 375) then
y := y + 5
if y = 370 then
top := true
end if
end if
if chars (KEY_RIGHT_ARROW) and (x < 615) then
x := x + 5
if x=610 then
right:=true
end if
end if
if chars (KEY_LEFT_ARROW) and (x > 0) then
x := x - 5
if x=0 then
left:=true
end if
end if
if chars (KEY_DOWN_ARROW) and y > 0 then
y := y - 5
if y=0 then
bottom:=true
end if
end if
if top = true then
drawline (0, maxy, maxx, maxy, red)
end if
if bottom = true then
drawline(0,0,maxx,0,red)
end if
if left= true then
drawline(0,0,0,maxy,red)
end if
if right= true then
drawline(maxx,0,maxx,maxy,red)
end if
drawbox (x, y, 20 + x, 20 + y, red)
delay (10)
cls |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Sun Dec 26, 2010 3:20 pm Post subject: RE:How can i get my code not to flacker?;D |
|
|
Use the site's search function. There are lots of tutorials on this, all of which tell you the same thing. |
|
|
|
|
![](images/spacer.gif) |
ProgrammingFun
![](http://compsci.ca/v3/uploads/user_avatars/11682880074bcb590d30b0a.png)
|
Posted: Sun Dec 26, 2010 3:21 pm Post subject: Re: How can i get my code not to flacker?;D |
|
|
EDIT: I didn't notice that Insectoid already posted
You should try to use View.offscreenonly (I have forgotten if it looked exactly like that) to draw the shapes...this would diminish the flickering.
Please try to use the given template when posting questions and plz also try to use syntax tags like the following:
Syntax: |
No "-" should actually be in the brackets (I used it so that it doesnt show up as a code block:
[-Syntax="turing"]Your code here...[/-Syntax]
|
so that you code would appear as follows:
Turing: |
var x, y : int
var top, bottom, left, right : boolean := false
x := 100
y := 100
var chars : array char of boolean
loop
Input.KeyDown (chars )
if chars (KEY_UP_ARROW) and (y < 375) then
y := y + 5
if y = 370 then
top := true
end if
end if
if chars (KEY_RIGHT_ARROW) and (x < 615) then
x := x + 5
if x = 610 then
right := true
end if
end if
if chars (KEY_LEFT_ARROW) and (x > 0) then
x := x - 5
if x = 0 then
left := true
end if
end if
if chars (KEY_DOWN_ARROW) and y > 0 then
y := y - 5
if y = 0 then
bottom := true
end if
end if
if top = true then
drawline (0, maxy, maxx, maxy, red)
end if
if bottom = true then
drawline (0, 0, maxx, 0, red)
end if
if left = true then
drawline (0, 0, 0, maxy, red)
end if
if right = true then
drawline (maxx, 0, maxx, maxy, red)
end if
drawbox (x, y, 20 + x, 20 + y, red)
delay (10)
cls
end loop | [/b] |
|
|
|
|
![](images/spacer.gif) |
munt4life
|
Posted: Sun Dec 26, 2010 3:34 pm Post subject: RE:How can i get my code not to flacker?;D |
|
|
I have but i still cant seem to get it to work ![Sad Sad](http://compsci.ca/v3/images/smiles/icon_sad.gif) |
|
|
|
|
![](images/spacer.gif) |
ProgrammingFun
![](http://compsci.ca/v3/uploads/user_avatars/11682880074bcb590d30b0a.png)
|
Posted: Sun Dec 26, 2010 5:37 pm Post subject: RE:How can i get my code not to flacker?;D |
|
|
The following was taken from the Turing FAQ:
TheOneTrueGod @ Sun Jun 04, 2006 9:19 am wrote: Q: Why is my program flickery?
Ans: You aren't using View.Set ("offscreenonly") and View.Update or you aren't using them properly.
The order of code should be as follows:
code: |
View.Set("offscreenonly") % Make sure this is spelled EXACTLY as is.
loop
% Draw your images before the View.Update
%Notice this gap here. DO NOT 'View.Update' WHILE you are drawing. 'View.Update' AFTER you are done drawing.
View.Update
% delay (preferably using Time.DelaySinceLast)
cls
end loop
|
If "offscreenonly" is not spelled right, it will not work.
Generally, if you have more than one View.Update, you're using it wrong. (This includes if you have it inside a for loop somewhere)
An explanation:
View.Set('offscreeonly') will initiate double buffering. This means Turing will draw everything to a "back buffer", which is invisible, elsewhere. Its an 'imaginary' piece of space somewhere in memory. You will never see what is being drawn there until you 'flip' it onto the screen, using View.Update. "View.Update" copies the entire back buffer to the front buffer, where it becomes visible in the Turing run window. This is why, when you use offscreenonly, you cannot see what you are writing when you use the command "get".
To remedy the "I can't see what I'm inputting" problem, simply reset offscreenonly by using
code: |
View.Set('nooffscreeonly')
|
|
|
|
|
|
![](images/spacer.gif) |
SS1389
|
Posted: Sun Dec 26, 2010 6:09 pm Post subject: Re: How can i get my code not to flacker?;D |
|
|
Very nice way to utilize your resources. |
|
|
|
|
![](images/spacer.gif) |
ProgrammingFun
![](http://compsci.ca/v3/uploads/user_avatars/11682880074bcb590d30b0a.png)
|
Posted: Sun Dec 26, 2010 6:25 pm Post subject: Re: How can i get my code not to flacker?;D |
|
|
SS1389 @ Sun Dec 26, 2010 6:09 pm wrote: Very nice way to utilize your resources. Indeed...that was the point ![Rolling Eyes Rolling Eyes](http://compsci.ca/v3/images/smiles/icon_rolleyes.gif) |
|
|
|
|
![](images/spacer.gif) |
|
|