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

Username:   Password: 
 RegisterRegister   
 Moving Images
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
oopsidoodles




PostPosted: Thu Mar 13, 2014 12:06 pm   Post subject: Moving Images

For the past while I have been trying to move an image (a jpeg) and I have been 50% successful. The image does move, which is what I want, but the previous copy of the image stays there, so you have the same image copying itself over a bunch of times.

Nothing I tried seems to work. I tried using Pic.Free and even using cls (cleared entire screen as expected), but nothing seems to work.



code:

%Setting up window
View.Set ("graphics:max;max")
View.Set ("nobuttonbar")
View.Set ("noecho")
View.Set ("offscreenonly")

%Properties of mouse
var x : int
var y : int
var p : int

%Variables to do with reticle
var r : int := Pic.FileNew ("Reticle.jpg")



%Sets up all the initial drawings
procedure draw ()

    Draw.Line (0, ((maxy / 10) * 7) div 1, maxx, ((maxy / 10) * 7) div 1, 16)
    Draw.Fill (0, 0, 48, 16)
    Draw.Fill (0, maxy, 52, 16)

end draw



%Checks and stoes position of mouse
procedure check ()
    Mouse.Where (x, y, p)
end check



%Updates what it has to
procedure update ()
    Pic.Draw (r, x, y, picCopy)
end update



%Main procedure
procedure main ()

    draw ()

    loop

        check ()
        update ()
        View.Update ()

        delay (33)

    end loop

    quit

end main



%Calls main procedure
main ()




Any help would be greatly appreciated, thanks. This is a very annoying issue and I'd really like to finally be able to fix it.

EDIT: I did actually fix this, by clearing everything, then redrawing the background with the image, but if it's possible I'd rather just redraw the image as redrawing everything seems like an ugly way to fix the problem.
Sponsor
Sponsor
Sponsor
sponsor
evildaddy911




PostPosted: Thu Mar 13, 2014 2:28 pm   Post subject: RE:Moving Images

despite seeming ugly, thats the best way to solve the problem. there is another way to do it:
draw a box over the picture, then redraw. you would need to track where the mouse was last frame, draw a box the size of the picture at those coordinates (covering the pic), then redrawing the picture.
Your update() would look like
code:
Draw.FillBox (oldX, oldY, oldX + picWidth, oldY + picWidth, color) % cover pic at prev. location
Pic.Draw (r, x, y, picCopy) % draw the pic at current location
However, this should only be used when the background is a solid colour, which yours is not
Raknarg




PostPosted: Thu Mar 13, 2014 3:33 pm   Post subject: RE:Moving Images

The best way is to clear the screen and redraw everything. It's simple and makes the most sense. Maybe it seems ugly when you have one thing to redraw, but what if you have 500 things to redraw or more? It's more efficient to just clear your entire screen.

Turing:

setscreen("offscreenonly")

for i : 1 .. maxx
    Draw.FillOval(i, 50, 25, 25, 12)
   
    View.Update
    delay(2)
    cls
end for


Now no matter how many items you have, the whole thing is reset by three easy lines of code at the end of the loop.
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  [ 3 Posts ]
Jump to:   


Style:  
Search: