Jump to content
IGNORED

Another cool thing: fixed point math


Random Terrain

Recommended Posts

I was moving a sprite left and right and tried to slow it down with a counter. Looked like crap. I also tried to speed it up by adding or subtracting 2. Looked like crap. I then tried fixed point math. Whether you slow it down or speed it up to something like 1.5, it just looks smoother. I even cranked it up to 3.5 and it still looked pretty good. After playing around with fixed point math, there's no way I'd use a counter or plain old regular numbers again for sprite movement.

Link to comment
Share on other sites

I used a counter for my "TZ" demo, and I think sprite movement is pretty smooth. I start the single variable used at 50 though, and increase velocity depending on how far the variable moves toward 0 or 100. I prefer this method for the sake of saving a precious variable.

Link to comment
Share on other sites

I used a counter for my "TZ" demo, and I think sprite movement is pretty smooth. I start the single variable used at 50 though, and increase velocity depending on how far the variable moves toward 0 or 100. I prefer this method for the sake of saving a precious variable.

Do you have time to make a quick, small program where you can move a simple object around the screen using your technique? Since there would be no extra code for other things, it would be easier to understand and follow.

 

 

Thanks.

Link to comment
Share on other sites

  • 1 year later...

I was moving a sprite left and right and tried to slow it down with a counter. Looked like crap. I also tried to speed it up by adding or subtracting 2. Looked like crap. I then tried fixed point math. Whether you slow it down or speed it up to something like 1.5, it just looks smoother. I even cranked it up to 3.5 and it still looked pretty good. After playing around with fixed point math, there's no way I'd use a counter or plain old regular numbers again for sprite movement.

Do you have a code example of this? I've been looking for a good example of fixed point variables but I haven't found one yet.

Link to comment
Share on other sites

I used a counter for my "TZ" demo, and I think sprite movement is pretty smooth. I start the single variable used at 50 though, and increase velocity depending on how far the variable moves toward 0 or 100. I prefer this method for the sake of saving a precious variable.

Do you have time to make a quick, small program where you can move a simple object around the screen using your technique? Since there would be no extra code for other things, it would be easier to understand and follow.

 

 

Thanks.

You can use fixed-point math for moving players without using an extra variable and without needing to do something like Maus is suggesting.

 

When you set up your variables, do this:

 

dim p0pos = player0x.a

 

Then you may add a 4.4 or an 8.8 to p0pos and it will move your player, and you don't need to waste a variable - in this example, a becomes the fractional portion of player0x.

Link to comment
Share on other sites

Something like this?

  set romsize 4k


playfield:
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X..............................X
X..............................X
X..............................X
X..............................X
X..............................X
X..............................X
X..............................X
X..............................X
X..............................X
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
end
    
    player0x=50
    player0y=50


    dim p0pos=player0x.a
    dim p0posy=player0y.b

    
main


COLUP0=28
COLUBK=22



player0:
001111
001111
001111
001111
end



drawscreen


if joy0right then p0pos=p0pos+1.5
if joy0left then p0pos=p0pos-1.5
if joy0up then p0posy=p0posy-1.5
if joy0down then p0posy=p0posy+1.5

 
goto main

Edited by accousticguitar
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...