Results 1 to 3 of 3
  1. #1
    Antigol is offline Member
    Join Date
    Aug 2009
    Posts
    1
    Rep Power
    0

    Default Moving objects - setting different speed

    Hi, sorry my english.

    I'm making a football game in Java. I tried to make it in other languages in the past (delphi and vb6) and in all of them I had the same question which I can't even now solve.

    It might be a conceptual one, that's why Im asking here.

    I have a class player which calculates where a player should move (an X and Y point) and then through some math calculations I get whether he should move 1 or 0 of X and 1 or 0 of Y to reach that point.

    So if my player is on X:200,Y:200 and he has to move to X:400,Y:400, he will move 1 of X and 1 of Y each time my timer is fired until he reaches point 400,400.

    To show the player's movement to the user, I have a timer which is launched each 1 ms (it fires an event who moves the player by repainting) and it works fine (I can see my players moving through the screen). But the problem is that even using 1ms my players only move in a normal speed. I can't make my fastest player to move more quickly. I can do this only by moving him 2 by 2 instead 1 by 1 but when you see the player's movement you can see the "jumps" he does.

    How can i simulate different speed in player's movement?

    Thanks in advance.

  2. #2
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    The only way is to slow down how quickly the 'normal' speed timer fires.

    e.g

    Very Fast: 1 ms
    Fast: 2 ms
    Normal: 3 ms
    Slow: 4 ms
    Very Slow: 5 ms

    This will simulate different movement speeds for the players.
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  3. #3
    Mr.Beans's Avatar
    Mr.Beans is offline Senior Member
    Join Date
    Apr 2009
    Location
    Virginia Beach, Virginia
    Posts
    149
    Rep Power
    0

    Default

    What I would do is map the world to a floating point coordinates system (or some sort of adjusted size coordinate system), and just fire the timer off more often. I'm guessing that the x,y that you are using are actual pixels on the window. That makes it so that if someone is going 1 pixel per second, the next fastest person has to be going twice as fast.

    Someone going 1.25 and someone going 1.50 would be much more realistic.

    Mr. Beans

Similar Threads

  1. Improve write speed
    By Krons in forum Advanced Java
    Replies: 10
    Last Post: 04-16-2009, 07:30 AM
  2. Test internet speed
    By kalpo in forum Networking
    Replies: 0
    Last Post: 03-31-2009, 01:20 AM
  3. How to speed sql Statements?
    By bezudar in forum Advanced Java
    Replies: 3
    Last Post: 11-20-2008, 10:53 AM
  4. examples of moving objects
    By fred in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 07:06 PM
  5. compare speed
    By bbq in forum JDBC
    Replies: 1
    Last Post: 06-28-2007, 06:34 PM

Posting Permissions

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