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

Username:   Password: 
 RegisterRegister   
 keeping your backround while clearing something infront ofit
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
DanceMacabre




PostPosted: Sat May 06, 2006 10:47 am   Post subject: keeping your backround while clearing something infront ofit

Now then. I've drawn a grid as a backround, and I want the player to control the square while I still have a grid drawn in the backround. The problem is (To my knowledge anyway) I cannot Draw.Cls my box unless I want to get rid of the backround aswell. I want to keep the backround when I Draw.Cls my square. The problem I face is I don't know how to do that! Any help is appreciated. Heres my code:
code:

var gridx : int := 0
var gridy : int := maxy
var space : int := Pic.FileNew ("space.jpg")
var paranoids : int := Pic.FileNew ("paranoids.jpg")
var x : int := 52
var y : int := 42
var sx : int := 350
var sy : int := 350
var charpress : array char of boolean
var enter : char
var fontid := Font.New ("ZapfHumnst BT:40x25")
var cursorx : int := 60
var cursory : int := 102
var key : string (1) := ""


View.Set ("graphics")
drawfillbox (0, 0, maxx, maxy, black)
loop
    delay (50)
    drawfillbox (gridx, 0, gridx - 1, maxy, brightblue)
    gridx := gridx + 25
    exit when gridx > maxx
end loop
gridx := 0
loop
    delay (50)
    drawfillbox (0, gridy, maxx, gridy - 1, brightblue)
    gridy := gridy - 25
    exit when gridy < 0
end loop

Music.Play ("d")
drawfillbox (0, 0, 10, maxy, black)
delay (500)
Music.Play ("d")
drawfillbox (maxx - 10, 0, maxx, maxy, black)
delay (500)
Music.Play ("d")
drawfillbox (0, maxy, maxx, maxy - 5, black)
delay (500)
Music.Play ("d")
drawfillbox (0, 5, maxx, 0, black)
delay (1000)
Music.Play ("a")
Pic.Draw (space, 11, maxy - 47, picMerge)
delay (200)
Music.Play ("a")
Pic.Draw (paranoids, 11, maxy - 88, picMerge)
delay (1000)
Draw.FillBox (195, 195, 504, 303, black)
for z : 199 .. 500
    delay (1)
    Draw.Box (z, 199, 500, 299, blue)
end for
Font.Draw ("PLAY", 225, 235, fontid, brightblue)
% Draw.FillBox(,,,,black)
Draw.FillBox (15, 46, 319, 154, black)
for decreasing z : 315 .. 19
    delay (1)
    Draw.Box (19, 50, z, 150, blue)
end for
Font.Draw ("QUIT", 100, 87, fontid, brightblue)

%*************************************************%
%++++++++++++++draw the characters++++++++++++++++%
%*************************************************%

var keys : array char of boolean
View.Set ("graphics,offscreenonly")
var x1, y1 : int := 0
const size : int := 5
y1 := maxy - size
cls
loop
    Draw.FillBox (0, 0, maxx, maxy, black)
    drawfillbox (gridx, 0, gridx - 1, maxy, brightblue)
    gridx := gridx + 25
    delay (50)
    drawfillbox (0, gridy, maxx, gridy - 1, brightblue)
    gridy := gridy - 25
    loop
        Input.KeyDown (keys)
        if keys (KEY_DOWN_ARROW) then
            loop
                y1 -= 1
                Draw.Cls
                Draw.FillBox (x1, y1, x1 + size, y1 + size, brightred)
                View.Update
                exit when hasch
            end loop
        end if
        if keys (KEY_RIGHT_ARROW) then
            loop
                x1 += 1
                Draw.Cls
                Draw.FillBox (x1, y1, x1 + size, y1 + size, brightred)
                View.Update
                exit when hasch
            end loop
        end if
        if keys (KEY_LEFT_ARROW) then %%%
            loop
                x1 -= 1
                Draw.Cls
                Draw.FillBox (x1, y1, x1 + size, y1 + size, brightred)
                View.Update
                exit when hasch
            end loop
        end if
        if keys (KEY_UP_ARROW) then %%%
            loop
                y1 += 1
                Draw.Cls
                Draw.FillBox (x1, y1, x1 + size, y1 + size, brightred)
                View.Update
                exit when hasch
            end loop
        end if
    end loop
end loop

Wink
Sponsor
Sponsor
Sponsor
sponsor
HellblazerX




PostPosted: Sat May 06, 2006 11:44 am   Post subject: (No subject)

I guess the only way to do this is to replace the Draw.Cls command with a procedure of your own that will draw the background instead of clearing the screen. There's no way you can set the cls command to draw your background.
codemage




PostPosted: Mon May 08, 2006 7:44 am   Post subject: (No subject)

If you're on version 4.1, there's a View.UpdateArea command that should be able to just update your player without having to reflash the whole screen.
[Gandalf]




PostPosted: Mon May 08, 2006 3:02 pm   Post subject: (No subject)

codemage wrote:
If you're on version 4.1, there's a View.UpdateArea command

I'm pretty sure View.UpdateArea was also available for Turing 4.0.5.

Problems like this are generally solved by redrawing the entire screen at each iteration of your main loop, background and all.
Bored




PostPosted: Mon May 08, 2006 9:05 pm   Post subject: (No subject)

Also if your on a version of Turing supporting Sprites (I beleive 4.1 and 4.0.3 or below) you can create a sprite for the picture you are drawing over the background and simply hide it, show it, and move it when needed all without affecting you background.
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  [ 5 Posts ]
Jump to:   


Style:  
Search: