1

I'm fairly new to C# and have mostly done Java. At the moment I am working on a project that has a spinning wheel and a spin button so its pretty simple. I've managed to get the wheel spinning it is currently 624 frames. i have set up a timer to handle the switch between images but as it spins its rather slow and i have interval set to 1 yet its still pretty slow takes about 10 secs to get through all 624 frames. i need it to be at least 4 secs for all 624 frames then gradually slow down.

here is some of my code below.

private void Spin_Click(object sender, EventArgs e)
    {// button to start the timer          
        if (spin == 0) {
            spin = 1;
            Random r = new Random();
            Console.WriteLine(r.Next(1, 53));
            spin = 0;
            st.Elapsed += new ElapsedEventHandler(OnTimedEvent);
            st.Interval = 1;
            st.Start();
        }

    }

    private static void OnTimedEvent(object source, ElapsedEventArgs e)
    {
        t1 = t1 + 1;
        Console.WriteLine("" + t1);
        if (t1 == 1)
        {
            Wheel.Image = global::WheelOfFortune.Properties.Resources.Wheel_Test_0001;
        }
        else if (t1 == 2)
        {
            Wheel.Image = global::WheelOfFortune.Properties.Resources.Wheel_Test_0002;
        } //etc x 624 then t1 = 0 to repeat

Any ideas would be great guys.

If you need further info let me know

wardas23
  • 79
  • 9
  • 2
    You actually wrote the if 624 times?! wow... – Black0ut Sep 03 '15 at 00:22
  • more like copy and paste and find and replace lol – wardas23 Sep 03 '15 at 00:24
  • 1
    Timers have fairly poor resolutions and you can't get them to fire every 1ms. I believe the the limit is around 15ms. – Enigmativity Sep 03 '15 at 00:28
  • eh it only took me 5 mins to copy and paste the code ill sort that out later – wardas23 Sep 03 '15 at 00:28
  • http://stackoverflow.com/questions/4212611/raise-event-in-high-resolution-interval-timer – pm100 Sep 03 '15 at 00:31
  • i see what you mean how else can i rotate between the images at a faster speed, i had timers in java and they did the trick they were so fast i had to slow them down. would i have to remove some frames? – wardas23 Sep 03 '15 at 00:31
  • 1
    624 images in 10 seconds is the speed at which the monitor repaints. You _cannot_ get any faster than that. – SLaks Sep 03 '15 at 00:33
  • Note that `Resources.XXX` will re-load the image every time it's accessed. You should cache that. – SLaks Sep 03 '15 at 00:33
  • See if this answer helps - http://stackoverflow.com/a/22862989/259769 – Enigmativity Sep 03 '15 at 00:37
  • I suspect you could use one wheel image and rotate it in code. You might want to try that approach. – default.kramer Sep 03 '15 at 00:43
  • @default.kramer their is also a peg on the wheel clicking over each slot on the wheel so unfortunately i don't think i can do that – wardas23 Sep 03 '15 at 01:09
  • @Enigmativity thanks this look like what i need to do but I can barely read what it does and how to implement it. – wardas23 Sep 03 '15 at 01:17
  • hmm if i increase t1 = t1 +1 to +6 it goes the speed i want and i can gradually change the number down to slow it down this seems to work. for some reason though the first spin goes perfect the second one goes messed up and glitches everywhere do i need to reset the timer somehow? – wardas23 Sep 04 '15 at 00:15

0 Answers0