Post: VB - Using Timers Help
03-31-2012, 11:32 PM #1
IamQwerty
You talkin to me?
(adsbygoogle = window.adsbygoogle || []).push({}); Ive created a Game like a Slot Machine and now I want to use some timers to make it better, Ive never used timers before so im completly lost here but have looked on net so have basic knowledge. For my Game im trying to use a timer so that it will rotate throught the pictures for a few seconds then stop. This might be hard to explain so i found a youtube video.



You see when he clicks the green button the images rotate and then stop evenually one by one thats what im trying to achieve but atm ive not idea how i can do this so im looking for some guidence here. I understand that im going to need to use 2 timers one for starting and one for stopping So can anyone Help me out?
(adsbygoogle = window.adsbygoogle || []).push({});

The following user thanked IamQwerty for this useful post:

Pichu
04-01-2012, 12:46 AM #2
Epic?
Awe-Inspiring
Originally posted by IamQwerty View Post
Ive created a Game like a Slot Machine and now I want to use some timers to make it better, Ive never used timers before so im completly lost here but have looked on net so have basic knowledge. For my Game im trying to use a timer so that it will rotate throught the pictures for a few seconds then stop. This might be hard to explain so i found a youtube video.



You see when he clicks the green button the images rotate and then stop evenually one by one thats what im trying to achieve but atm ive not idea how i can do this so im looking for some guidence here. I understand that im going to need to use 2 timers one for starting and one for stopping So can anyone Help me out?


So, I'll give you some sort of generic timer advice, followed by how you can apply it to your specific situation...

First off, .NET timers are similar to timers in the real world. They have an interval, you can start and stop them, and you can be notified when the timer "ticks" (when it's run for a given interval).

You can either drag-and-drop a Timer component on to your form from the toolbox, or you can create one just like how you might create any other object:
    Dim MyTimer As New Timer()


Timers can, like any other component, be enabled or disabled using the Enabled property:
    
MyTimer.Enabled = True ' The timer is enabled
MyTimer.Enabled = False ' The timer is disabled


You can set an interval for a Timer - this will indicate the number of milliseconds between ticks:
    MyTimer.Interval = 1000 ' The timer has a 1 second interval between ticks


From there, you can start and stop timers. When a timer is started, it is running, and will tick at the end of each interval. When a timer is stopped, it's inactive - doing nothing.
    
MyTimer.Start() ' The timer is running
MyTimer.Stop() ' The timer is no longer running


The most important aspect of the timer is provided by the tick. Now, to get access to the events, you'll either have to have dragged-and-dropped the Timer on to your form, or you'll need to declare your timer with events:
    WithEvents MyTimer As New Timer()


That way, you can declare a subroutine like so:
    
Private Sub TimerHandler(sender As System.Object, e As System.EventArgs) Handles MyTimer.Tick
' Your timer-handling code here
End Sub


The subroutine above (TimerHandler) will be called each time the timer ticks (remember, a tick happens after the amount of time given by the interval).

Note that if you've dragged-and-dropped the Timer component on to your form from the toolbox, you can simply double-click the Timer (this will automatically generate the subroutine stub for you to fill in).

Anyhow, the basic process is fairly simple. You create a Timer, set the interval. Then, you start the timer. The timer will tick periodically, in intervals that is dictated by the interval property. Each time the timer ticks, any subroutine subscribing to the tick event will be notified - effectively calling the subroutine.


To make your specific program work, you'll probably need to set the interval to something relatively low (so that the pictures change quickly, possibly with an increasing interval to indicate a decreasing change-speed) then on each tick, you'll want to change the picture. You can have multiple timers for each picture, allowing you to change the pictures at different intervals. After so many ticks, you'd want to stop the timer.

The following user thanked Epic? for this useful post:

Pichu
04-01-2012, 03:25 PM #3
IamQwerty
You talkin to me?
Originally posted by Epic
So, I'll give you some sort of generic timer advice, followed by how you can apply it to your specific situation...

Small Quote ^

I understand the whole logic of it and your information above will help me. Ill get a try at this later see if i can get it working. If not do you mind helping me again if needed?
04-01-2012, 03:47 PM #4
Epic?
Awe-Inspiring
Originally posted by IamQwerty View Post
Small Quote ^

I understand the whole logic of it and your information above will help me. Ill get a try at this later see if i can get it working. If not do you mind helping me again if needed?


Sure, I'm happy to help, but if you need it, you'll need to be more specific in your question (as it was somewhat open-ended in your original post).

The following user thanked Epic? for this useful post:

Pichu
04-01-2012, 06:08 PM #5
IamQwerty
You talkin to me?
Originally posted by Epic
Sure, I'm happy to help, but if you need it, you'll need to be more specific in your question (as it was somewhat open-ended in your original post).


ok Thanks, ill get testing it out later and see,
If you watch the video from my first post from 10seconds to 14 seconds you can see each picture box rotate the different images and then stop
That is what im trying to achieve im sure its done with timers, Can you understand it from the video?
Thanks
04-01-2012, 06:16 PM #6
Epic?
Awe-Inspiring
Originally posted by IamQwerty View Post
ok Thanks, ill get testing it out later and see,
If you watch the video from my first post from 10seconds to 14 seconds you can see each picture box rotate the different images and then stop
That is what im trying to achieve im sure its done with timers, Can you understand it from the video?
Thanks


Yes, I can understand that, and if you read my first post (especially the part at the bottom), then you would know the general algorithm for implementing such a program. If you have an actual question, please let me know.

The following user thanked Epic? for this useful post:

Pichu
04-02-2012, 06:02 PM #7
IamQwerty
You talkin to me?
Originally posted by Epic
Yes, I can understand that, and if you read my first post (especially the part at the bottom), then you would know the general algorithm for implementing such a program. If you have an actual question, please let me know.


Thanks for the information i managed to get this implemented into my code and it works perfect
04-17-2012, 06:07 PM #8
IamQwerty
You talkin to me?
Originally posted by Epic
Yes, I can understand that, and if you read my first post (especially the part at the bottom), then you would know the general algorithm for implementing such a program. If you have an actual question, please let me know.


Im quoting you again as i need some more help :P wondering if you could help
Related to timers

Basicly i got the timers working as that they will rotate my pictures and eventually stop but now i have to add a points system to this so when two images show up which are the same the game will add 50 points. This is Where my problem comes in, while my images are rotating if two of them come up the same while it is rotating the game will add 50 points. I Only want it to add the 50 Points when the images have stopped rotating but i cant get this to work. Here is some code below, if they isnt too helpful i have added the code to a seperate program just to get it working and could possibly send it to whoever if they are willing to help.


If TimerLimit < 100 Then
ROTATE THE IMAGES
Else
Timer1.Enabled = False
TimerLimit = 0
End If


Ive tried creating another If statement after this saying If timer1= False then the code for the points but it still adds the points while it rotates
Can anyone see where im going wrong?
All of this above most likely sounds really confusing lol I can send the program
Thanks
04-27-2012, 05:43 PM #9
IamQwerty
You talkin to me?
Anyone help me with the problem above? i have got the pictures spinning but while they are spinning the it will carry out the calculations i need it to carry out the calculations once the spin has stopped

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo