Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Game Development and the fly likes Movement problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Game Development
Bookmark "Movement problems" Watch "Movement problems" New topic

Movement problems

Kris Chad

Joined: Apr 01, 2012
Posts: 1
Hello.Currently I'm making projectiles for a mini-game of mine,but I'm having movement problems with my code.I was originally going to use the same strategy I used to create and move the player,but that would require making the projectile upon login,not on command.Right now,the code will make a bullet in the starting area,wait a couple seconds,then make one in the ending area.How would I fix this so that it actually looks like its moving across the screen?Here is my code.

By the way,I know why it's not working,I just don't know how to fix it.
Phil Freihofner
Ranch Hand

Joined: Sep 01, 2010
Posts: 119
Have you looked into the "game loop" pattern. Basically, a loop repeatedly calls two commands, one to calculate current positions, the second to do the repaint.

As you get further into it, there are issues as to how to make the timing even for each loop. Some people take a timing reading before and after the two commands, and subtract the elapsed time from a desired total loop time to calculate a sleep amount. Another approach is to use a Timer (util.Timer is my preference) and give it a TimerTask with the two commands, and set it to repeat at the desired interval.
I agree. Here's the link:
subject: Movement problems
It's not a secret anymore!