Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 How can i get my code not to flacker?;D
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
munt4life




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: 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.
ProgrammingFun




PostPosted: 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 Shocked

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]
munt4life




PostPosted: 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
ProgrammingFun




PostPosted: 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')

SS1389




PostPosted: 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.
ProgrammingFun




PostPosted: 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
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: