×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    24

    Delay in Drawing ...

    I'm developing a card game.

    All the Graphics are being painted by paint() method ..

    The method should paint the Actual Player cards, wait for couple of seconds, then paints the Artificial Player cards ...

    I tried to insert this piece of code in order to get the delay between the moves :


    Code:
    draw_actual_player_cards;
    if(artificial_player_turn==1){
       for (int i=0 ; i<10000000; ++i);
       draw_artificial_player_cards;}

    The problem now is that the delay always take effect for both ( draw_actual_player_cards and draw_artificial_player_cards).

    Thats let assume the the delay lenght = x ..

    Then x time will pass then both paintings are displayed on the same time.

    While what I want is :

    the actual player cards are displayed -> delay of x -> the artificial payed cards are displayed

    So how can I adjust the code so i get proper display order with the desired delay??

  2. #2
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    Most MIDP devices are automatically double-buffered, so the backbuffer is only flushed at the end of the paint routine and you will only see the end result. To get the effect you want you will have to use a thread or a timer to repaint the screen twice, once with the player's cards only, and then again with all the rest of the cards.

    shmoove

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    24
    Thnx ..

    Can I have any example for that ??

  4. #4
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    Code:
    boolean drawAllCards;
    public void run() {
      drawAllCards = false;
      repaint();
      serviceRepaints();
      try {
        Thread.sleep(SOME_TIME);
      }
      catch (Exception e) {
      }
      drawAllCards = true;
      repaint();
      serviceRepaints();
    }
    
    public void paint(Graphics g) {
      drawPlayerCards(g);
      if (drawAllCards) {
        drawOpponentCards();
      }
    }
    shmoove

  5. #5
    Registered User
    Join Date
    Mar 2003
    Posts
    24
    I did the necessary modifications as above ...
    Last edited by mudhahka; 2004-07-11 at 19:12.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •