Hopefully a simple problem....

Discussion in 'Programming General' started by slashshot007, Dec 7, 2008.

Hopefully a simple problem....
  1. Unread #1 - Dec 7, 2008 at 9:59 AM
  2. slashshot007
    Joined:
    May 6, 2006
    Posts:
    164
    Referrals:
    0
    Sythe Gold:
    0

    slashshot007 Active Member

    Hopefully a simple problem....

    for making games, in java, how would i make it so i can, for example, make a ball bounce, without using a timer?
    I made a super cool breakout game(not really that great) but the problem is, it isn't the fastest, becuase the ball moves through a timer.

    so how do i do this without a timer? (i dont use an applet, i have everything in a "BreakoutPanel" which extends JPanel)

    (I'll release the source to the breakout game when it is completely finished)

    thanks in advance.
     
  3. Unread #2 - Dec 7, 2008 at 10:32 AM
  4. Swan
    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner

    Swan When They Cry...
    Retired Global Moderator

    Hopefully a simple problem....

    Does it not make sense to use a timer? What you need to get correct is the speed of the ball, as well as other forces involved. A timer simply serves as a refresher.

    Of course, you could fashion your own timer as well, I believe. All you need to do is create a new thread which measures milliseconds. I'm not sure how you would do it in Java, but in .Net I would call the Windows GetTickCount() API twice (returns a millisecond value of how long the computer has been running) and find out the difference between them. I'm unsure how else to do it, but whenever I've done anything similar to this, I've used timers or threads.
     
  5. Unread #3 - Dec 7, 2008 at 10:54 AM
  6. Nullware
    Joined:
    Jan 30, 2007
    Posts:
    1,761
    Referrals:
    4
    Sythe Gold:
    0

    Nullware Guru

    Hopefully a simple problem....

    Code:
    long currentTime = System.currentTimeMillis();
    To make it into a timer you would just take the current time prior to starting the operation(s) and then take the current time again after, substract them, and continue if a certain amount of time has elapsed and loop again if it hasn't.
     
  7. Unread #4 - Dec 7, 2008 at 11:02 AM
  8. slashshot007
    Joined:
    May 6, 2006
    Posts:
    164
    Referrals:
    0
    Sythe Gold:
    0

    slashshot007 Active Member

    Hopefully a simple problem....

    ok, well i wasn't planning on actually makinga timer, but to use it without.
    but anyways the solutions was threads, i looked it up, and it works great now.
    I just wasn't familiar with threads at all, but they are VERY convenient, and I will use them LOTS in the future.
     
< Create a new copy of a tab | How to log into a vBulletin forum >

Users viewing this thread
1 guest


 
 
Adblock breaks this site