Page 1 of 1

Smoother sprite movement...

Posted: Sun Jan 25, 2009 6:14 pm
by Sylus101
Hey everyone,

This is a general game coding question and not specific to libnds, but since it's the library I'm working with I figured I'd post here. I'm working on the acceleration of a running sprite character, i.e. starting slowly and increasing in velocity.

I'm working with 2 different methods and have basically the same issue with both. The issue is trying to achieve a smoother sprite movement when working with certain speeds. With both counters and fixed points, you can get movement that does moves 1 pixel every other vbl, every 3rd (with counters...) or every 4th smoothly. You can easily get 2 pixels per vbl, 3, or 4 etc...

My issue is with something in-between. The jump in speed to me, at least for my games needs, from 1:1 to 2:1 (pixels:vbl) is too much. What I want is 1.5:1 or 3:2.

With fixed points ( using bit shift by 8 ) having a velocity of 384 (1.5) would be the correct amount, but the issue is that movement ends up being 1 pixel, 2 pixels, 1 pixel, 2 pixels and so on. Pretty choppy if you ask me...

With counters, I can move 2 pixels after waiting 3 vbls... which I thought would be much better, but still definitely noticeably choppier than moving 1:1 or 1:2 or 2:1, etc...

So is this just the nature of the beast, or am I missing something obvious? What I was trying to achieve, was a transition from 1:2, 2:3, then 1:1. The choppiness at 2:3 is pretty noticeable...

Re: Smoother sprite movement...

Posted: Mon Jan 26, 2009 4:24 am
by afireohno
I think it is just "the nature of the beast" as you said, since half of a pixel doesn't really exist. However, I'm far from experienced and I may be missing something as well.

I wonder if it would be possible to somehow trick the eye into thinking it moved half a pixel. Maybe something like anti-aliasing. If anyone has answer, or if you figure something out, I would be very interested in the solution.

Re: Smoother sprite movement...

Posted: Mon Jan 26, 2009 6:08 am
by Sylus101
Well, I posted on another forum the same question and ran a few other tests. Fixed point really appears to be the only way to go and had better results than I recalled.

What I'm going to end up going with (or very close to it) is doing bit-shifts of 12 making 4096 my velocity for moving 1 pixel per vbl. Moving up or down by increments of 256 actually worked pretty well, but that's 1/16th when shifted down so I might go with 512 instead as 1/8th increments will probably suffice.

Re: Smoother sprite movement...

Posted: Mon Jan 26, 2009 7:54 am
by WinterMute
Try rounding up when you convert to integers for the sprite display, that can help a bit. Generally fixed point is about your best option for this kind of thing