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

Username:   Password: 
 RegisterRegister   
 need help with simple animation
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Hendo




PostPosted: 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?
Sponsor
Sponsor
Sponsor
sponsor
Reality Check




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




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




PostPosted: 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.
Reality Check




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




PostPosted: 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
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  [ 6 Posts ]
Jump to:   


Style:  
Search: