Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Movement problems

 
Kris Chad
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 121
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic