Lec19 - Lecture 19: Timers & Animation PIC 10C Todd...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Lecture 19: PIC 10C Todd Wittman Threading s Blocks of code that run concurrently with the main program are called threads . s Programming these blocks so that all the pieces of the program work together is called threading . s One example of threading is to have a procedure that executes at set time intervals. s This could be useful for animations -- we would draw a new image frame every interval.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Timer s The Timer control is like a stopwatch that allows you to keep track of time as your program runs. s There aren't many properties for the Timer. s Enabled -- true if you want the clock to be running s GenerateMember -- whether you want it to generate an object s Interval -- how often you want the Tick() event to occur. Default is 100 milliseconds. Timer s The important functions are: s timer.Start() -- start the clock running (Enabled=true) s timer.Stop() -- stop the clock (Enabled=false) s Note by default the Timer is disabled, so you have to tell it when to Start. s The Tick() event of the Timer is fired every time an Interval elapses. s For example, to animate a picture we would draw in Tick(). private void animationTimer_Tick(object sender, EventArgs e) { Move objects a little bit g.DrawStuff(); this.Refresh(); }
Background image of page 2
3 Example: Moving in Circles s Ex Animate a rectangle so that it moves around in a circle. s
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 8

Lec19 - Lecture 19: Timers & Animation PIC 10C Todd...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online