Question about Timers

  1. 11 months ago

    I am creating a card game and need some help with Timers.

    I am planning on using a Timer to make it look like a card is being taken from the deck and added to a player's hand. At the start each player draws 5 cards. Can I use one Timer for all drawing cards or should I have one Timer for the first hand and a separate one to each any subsequent draws?

  2. Roger C

    10 Aug 2017 Lewis Center, OH

    Use a single timer. Have that timer's action event call a method which does the logic to determine which card is being animated.

  3. I tried that except the timer for some reason doesn't activate until player 2's card are being dealt.

    In the Method that calls the Timer to draw 5 card for each player:

    intPlayer = intWhoGoesFirst
    intDrawNumber = 5
    tmrDraw.Mode = 2

    But this block of code doesn't get activated and is completely skipped. Is there a way to pause after the Timer is activated and wait until the timer is turned off before executing the next block of code.

  4. Roger C

    10 Aug 2017 Lewis Center, OH

    Set the timer.mode = 1
    The timer fires once then turns itself off. When you need it again, set

    myTimer.mode = 1

    once again

  5. I already tried that but it still skips all code regarding the Timer until the last call in the Method.

    To draw 5 cards I did this:

    tmrDraw.Mode = 1
    tmrDraw.Mode = 1
    tmrDraw.Mode = 1
    tmrDraw.Mode = 1
    tmrDraw.Mode = 1

    Only the last tmrDraw.Mode = 1 activates skipping the other 9 calls.

  6. Roger C

    10 Aug 2017 Lewis Center, OH

    What are you trying to accomplish by calling your timer 5 times in a row with no intervening code?
    Don't set the timer.mode until some other task has been completed.

  7. I have to draw 5 cards for each player. That's why I asked if I should one timer for the initial 10 card draw and a separate timer for when only one card is drawn.

  8. Roger C

    10 Aug 2017 Lewis Center, OH

    Please show your code which animates the drawing of a single card.

  9. Greg O

    11 Aug 2017 Xojo Inc Somewhere near Raleigh, NC

    @Charles F
    Timers fire Asynchronously. That means that once you set them they fire outside of the scope of the code you are currently runnung.

    What roger was proposing was that you reset the mode of your timer at the end of the Timer.Action event.

  10. Edited 11 months ago

    I guess I will have to use 2 different timers, one for setting up the initial 5 card hand for each player and one for only drawing one card.

    Any timer I have in my project already has the code at the end to turn the timer to mode = 0.

  11. Roger C

    11 Aug 2017 Lewis Center, OH

    No, you don't have to. If you'll show us your code, we'll show you how to handle it better. Post the code in those timers you mention.

  12. Dave S

    11 Aug 2017 San Diego, California USA

    If the timer is meant to control the animation of the card moving, and only one card is moving at a time...
    a single timer should work

    1. start timer with a period of "x" where x dictates how FAST the card will move
    2. the timer should be MULTIPLE mode
    3. on each fire of the timer, move the card one "increment" towards its destination
    4. repeat until card reaches destination
    5. turn off the timer

    The same could be done to move multiple cards, but that is a bit more tricky

  13. All the code does in the timer is add one card to the players hand. It's not actually animated going from the deck to the hand. It just calls the DrawCard method which adds the card to the canvas and then calls the Invalidate(False) method to make the card appear.

or Sign Up to reply!