Computer Science Canada

need help with simple animation

Author:  Hendo [ Mon Feb 26, 2007 10:18 am ]
Post subject:  need help with simple animation

i use this code to draw a basic looking animated cloud.

code:
var x, y : int
x := 70
y := maxy-50
loop
x := x + 1
Draw.FillOval (x, y, 25, 25, white)
Draw.FillOval (x-25, y-20, 25, 25, white)
Draw.FillOval (x-15, y-40, 25, 25, white)
Draw.FillOval (x+15, y-40, 25, 25, white)
Draw.FillOval (x+45, y-40, 25, 25, white)
Draw.FillOval (x+50, y-20, 25, 25, white)
Draw.FillOval (x+30, y, 25, 25, white)
View.Update
delay (10)
exit when x=maxx-70
end loop


what this does though is leave a big trail behind it. I know I either have to redraw everything that is not animated or do something else to fix this. It works if i redraw the rest of the "non-animated" parts but it goes really slow...just wondering if there is a better way?

Author:  Reality Check [ Mon Feb 26, 2007 3:24 pm ]
Post subject:  Re: need help with simple animation

code:

var x, y : int
x := 70
y := maxy-50
loop
x := x + 1
Draw.FillOval (x, y, 25, 25, white)
Draw.FillOval (x-25, y-20, 25, 25, white)
Draw.FillOval (x-15, y-40, 25, 25, white)
Draw.FillOval (x+15, y-40, 25, 25, white)
Draw.FillOval (x+45, y-40, 25, 25, white)
Draw.FillOval (x+50, y-20, 25, 25, white)
Draw.FillOval (x+30, y, 25, 25, white)
View.Update
delay (10)
exit when x=maxx-70
end loop


First things first. I have no idea why you have all of those draws. All you need is one since your program loops and re-draws according to new values. Secondly, when using View.Update, accompany it with a setscreen ("offscreenonly"). This means that is does the calculations OFF the screen and updates the new one. This prevents flickering. Finally, you were missing a cls to clear your old picture. Here is your fixed up code.

code:

setscreen ("offscreenonly")
var x, y : int
x := 10
y := maxy - 50
loop
    x += 1
    Draw.FillOval (x, y, 25, 25, black)
    delay (10)
    View.Update
    cls
    exit when x = maxx - 70
end loop

Author:  Hendo [ Tue Feb 27, 2007 9:15 am ]
Post subject:  Re: need help with simple animation

i don't know about you, but my clouds usually look like more than 1 circle (hence why I have all those Draw.Ovals) I have other things in the picture besides the cloud and using cls erases all of it. It's an assignment for school and I'm making a scenery.

Author:  HellblazerX [ Tue Feb 27, 2007 1:58 pm ]
Post subject:  RE:need help with simple animation

Well, when you redraw the "non-animated" parts, the background, I'm assuming you're drawing them all separately, so what you could do is draw your background once, and save it as a picture using Pic.New, and redraw that one picture everytime instead of cls. That would be faster than redrawing everything separately.

Author:  Reality Check [ Tue Feb 27, 2007 8:42 pm ]
Post subject:  Re: need help with simple animation

Oh sorry. I didn't read the part that said cloud. I should read questions Sad

Author:  Hendo [ Wed Feb 28, 2007 7:49 am ]
Post subject:  Re: RE:need help with simple animation

HellblazerX @ Tue Feb 27, 2007 1:58 pm wrote:
Well, when you redraw the "non-animated" parts, the background, I'm assuming you're drawing them all separately, so what you could do is draw your background once, and save it as a picture using Pic.New, and redraw that one picture everytime instead of cls. That would be faster than redrawing everything separately.


hey, thats a good idea...i figured out the reason it was working so slow was just the computer i was using...i tried a different computer in the lab and it worked fine, i just put everything that wasn't animated into a procedure....but using Pic.New is probably even faster than that. Thanks Very Happy


: