Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

Smoothing out game control

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello I am currently working on my first pong / space shooter game, i have the pong aspect pretty much running fine in an applet, I am having a little trouble with smoothimg out the keyboard controls. I use the UP and DOWN key to control the Y pos of the blocker in the game. My problem is that i cant figure out how to make the blocker move more smoothly up and down the Y axis, here is my current code for when each button is pressed:

Is there somthing I can do numerically to smoothen my controls?

Thanks, Kp
[ July 22, 2005: Message edited by: Kevin Peterso ]
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kevin,

In my games, I implement what I call "inertia counters," which are integer variables that contain values that change over time. Specifically, there are two(2) such values: one for x-axis changes, and one for y-axis changes. The values can be either negative or positive. You can use a separate "thread" to manage how these values change per millisecond, which ultimately results in those values adjusting themselves so that they increment (or decrement) back to zero(0). Zero indicates no "movement" (i.e. no inertia). I use this technique in games that require "thrust" or "propulsion" of somekind, such that if the thrust key is released, these values (which contained the increment in x/y to "move" the ship) slowly revert back to zero - i.e. no thrust. Hope that makes sense. :-) In all, it always boils down to math.
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason why it is not smooth it is because you move it 20 pixels at a time.
You could move of 1 pixel instead of 20 and have an higher refresh rate,
this would make it smoother. What do you think???
a fool thinks himself to be wise, but a wise man knows himself to be a fool - shakespeare. foolish tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic