Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: 2D Smooth Character Control

24 Jun 2013   #1
Semicolon

Microsoft Windows 7 Ultimate 64-bit SP1
 
 
2D Smooth Character Control

I know this isn't primarily a programming forum, but everyone is so helpful I figured someone might be able to help. I am currently working on a 2D game in Java and have a character moving on a 2D plane. Right now the control is pretty choppy and I would like to smooth it out. Here is the relevant code I have:
Code:
	public void moveUp() {
		if(dy-1 > -maxSpeed){
			dy--;
		}
	}

	public void moveLeft() {
		if(dx-1 > -maxSpeed){
			dx--;
		}
	}

	public void moveDown() {
		if(dy+1 < maxSpeed){
			dy++;
		}
	}

	public void moveRight() {
		if(dx+1 < maxSpeed){
			dx++;
		}
	}

	public void update(applet applet) {
		distanceToCentre = Math.sqrt((x+dx+(size/2)-1-349)*(x+dx+(size/2)-1-349)+(y+dy+(size/2)-1-349)*(y+dy+(size/2)-1-349));
		if(distanceToCentre>340){
			dx=0;
			dy=0;
		}
		x += dx;
		y += dy;
		System.out.println(x + " " + y + " " + distanceToCentre);
	}
I was thinking about using some sort of function that the derivative gets smaller as the input increases (like log(x)/log(10)) but using log in Java takes too long.
My System SpecsSystem Spec
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar help and support threads
Thread Forum
How much RAM will I need to run Skyrim smooth?
Here are my current computer specs: Intel Pentium 4 CPU 3.60GHz 2.00 GB RAM 32-bit Operating System AMD Radeon HD 6800 Series I understand 2.00 GB is not a good amount for Skyrim as it continuously lags and freezes. What I need to know is how much RAM and/or other parts could I upgrade to...
Gaming
Smooth scrolling
Is there any was to make scrolling smooth ? Like when you have Google chrome with the "Chromium Wheel Smooth Scroller" extension installed but for everything in windows, not just the browser.
Customization
WMP Video too smooth
It's insane how smooth the video in WMP is. It's like someone went crazy with the texture smoothing filter in photoshop. Is there any way to control the codec rendering options? The "use video smoothing" option doesn't effect it as it's actually for smoothing playback of low bitrate stuttering...
Music, Pictures & Video
Smooth Edges
Hello everyone :). I am new here and I was just wondering if there was a way to make the open windows on Windows 7 look like a Mac, where it is smooth and sleek looking. Thanks!
Themes and Styles
Smooth scrolling?
Hi all! Scrolling seems very jumpy under Windows 7. You can especially notice it when scrolling through large icons in Windows Explorer. Is there a way to make it smoother? Thanks!
General Discussion
Slow deletes (character by character)
This probably has nothing to do with Windows 7, but I thought someone on this forum would know. When in a text editor like on this forum or on Microsoft word and when I delete and hold it down it will be really slow. Characters would only delete every half a second no matter what. Anyone...
General Discussion


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 19:39.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App