#4130 - TooTall - Thu Mar 20, 2003 1:48 am
Maybe a coding question but its in graphics now... I am trying to scroll a map smoothly in the direction my sprite is headed. At this point I have a clunky implentation based on a stored slope that I try to move the map along. What I would like is something similar to the background scrolling in thps2. Does anyone know if they did floating point stuff for that game? I did a brief search in the forum and didn't come up with any matches to my question. I am trying to do this in tilemode. Let me know if I can add anything else to my description or if this topic already exists here. Thank in advance.
TT
_________________
Knowledge speaks, wisdom listens.
-Jimi Hendrix
#4137 - DekuTree64 - Thu Mar 20, 2003 4:58 pm
Hmm, I don't know what thps2 is, but I can take a guess at what you're talking about^^ You mean like srolling when your character gets close to the edge of the screen, but don't keep him exactly in the middle, so you can move around a little in one area without scrolling all over the place?
What I'd do is have a distance from the edge of the screen where you start scrolling (say, 50 pixels), and then if your character is moving right, if his new position is less than 50 pixels from the edge of the screen, set BGX to character.x - (240 - 50). Or if he's moving left and gets within 50 pixels of the edge of the screen, set BGX to character.x - 50. Do that for up and down too, and you can run around and drag the map along with you whenever needed^^
Or if that's not what you meant, then sorry for the pointless explanation, but I'll need more info on exactly how you want it to move
#4147 - TooTall - Thu Mar 20, 2003 10:46 pm
I am actually trying to have a freely roamable map that my character can walk in any direction (360 degrees) not just 4 or 8 directions. I'm not yet worried about having the sprite walk up to the edge. thps2 = tony hawk pro skater 2.
TT
#4152 - tepples - Fri Mar 21, 2003 3:53 am
If you're using direct control of direction (Up = north, Down = south), and you don't have some sort of inertia requiring the player to build up momentum, then 360 degree motion is not possible because the GBA has digital controls. You'll have to switch to what Multimedia Fusion calls "race car" movement (Up = forward, Down = backward, Left = turn left, Right = turn right) to get anything approaching 360 directions, and you'll have to use the following bit of trig to calculate the velocity of the player.
Given: theta is the heading (0 = east, 90deg = north):
dx = speed*cos(theta)
dy = speed*(-sin(theta))
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#4172 - TooTall - Sat Mar 22, 2003 1:25 am
Im going to scale back my number of directions significantly. I'll keep your suggestion in mind anyway tepples.
TT
_________________
Knowledge speaks, wisdom listens.
-Jimi Hendrix
#4173 - col - Sat Mar 22, 2003 1:58 am
TooTall wrote: |
... I am trying to scroll a map smoothly in the direction my sprite is headed. At this point I have a clunky implentation based on a stored slope that I try to move the map along. ... Does anyone know if they did floating point stuff for that game? ...
TT |
My guess is that you need to go and read up on fixed point arithmetic.
(don't worry it's really simple when you get the hang of it)
If you store the coordinates of your sprite as fixed point numbers, you can move them by fractions.
Of course visible movement is in pixel units - you have to convert your coordinates to integers before applying them to the video hardware.
(the conversion is merely a right bit shift)
The overall impression is that things are moving in many directions/speeds smoothly.
(if i've missunderstood your post and you are already fully aware of fixed point numbers then sorry :))
Cheers
Col
#4248 - TooTall - Tue Mar 25, 2003 6:55 pm
col, when you talk about moving by fractions do you mean using floats as the internal representation and then converting to fixed for output? Or do you mean actual fractions? (that last one doesn't seem likely) From what I have read people dog floats as being slow. Is this accurate or is that just the super speed freaks optimizing their code to death? :) TT
#4250 - tepples - Tue Mar 25, 2003 8:06 pm
Floats are dog-slow, especially when you have 112 sprites moving about at once. Use fixed-point as the internal representation. Besides, more efficient code uses less battery power because more time is spent in VBlankIntrWait().
Fixed-point is a fraction with a constant denominator, generally set at a power of 2. For instance, the "24.8" fixed point uses 256 as a denominator; one is represented as 0x00000100, that is, 256/256.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#4366 - TooTall - Fri Mar 28, 2003 10:55 pm
I read up some on fixed point and am now using 20.12 for my internal representation of my world. It looks good and smooth when scrolling medium to fast but still shows alittle jerkyness when scrolling slowly. It's evenless noticeable on the hardware cause it's smaller:) Anyway thanks for your suggestions all...
TT
_________________
Knowledge speaks, wisdom listens.
-Jimi Hendrix