Hi I am having a bash at making myself a game on the gp2x but I have a question.
SDL_GetTicks() returns a Uint32 which is a unsigned whole number stored in 4 bytes I think.
My entity's position and velocity and acceleration are stored as int's.
I made the delta this: Uint32 delta = time_passed * 0.5; (The 0.5 is pulled out of a hat but it meens that if things are moving to fast I can make it smaller I hope)
Anyway my problems are that because the 0.5 is a double and the rest are integers I get a warning. Also if I set it to 0.3 I get no movement, 0.4 I get very slow movement and then 0.5 I get far too fast movement.
Anyway my question is am I doing this in a stupid way / how do you do it? As well because I heard that you shouldn't really use float's because the gp2x doesn't use them as well as integers but is it the same with doubles?
Here are some snipplets of how I am doing it.
This is my gameloop so you can see how I am figuring out the time_passed
This is the update function for my entity that figures out how much it should move
Thanks
edit: I think this should be in the "I need help (dev stuff only)" section actually but I don't think I can move it now, sorry.
SDL_GetTicks() returns a Uint32 which is a unsigned whole number stored in 4 bytes I think.
My entity's position and velocity and acceleration are stored as int's.
I made the delta this: Uint32 delta = time_passed * 0.5; (The 0.5 is pulled out of a hat but it meens that if things are moving to fast I can make it smaller I hope)
Anyway my problems are that because the 0.5 is a double and the rest are integers I get a warning. Also if I set it to 0.3 I get no movement, 0.4 I get very slow movement and then 0.5 I get far too fast movement.
Anyway my question is am I doing this in a stupid way / how do you do it? As well because I heard that you shouldn't really use float's because the gp2x doesn't use them as well as integers but is it the same with doubles?
Here are some snipplets of how I am doing it.
This is my gameloop so you can see how I am figuring out the time_passed
Code:
while (running == true)
{
Uint32 last_time = current_time;
current_time = SDL_GetTicks();
Uint32 time_passed = current_time - last_time;
get_input(&player);
player.draw(screen);
SDL_Flip(screen);
player.update(time_passed);
}
This is the update function for my entity that figures out how much it should move
Code:
void entity::update(float time_passed)
{
Uint32 delta = time_passed * 0.5;
int acc_x = force_x / mass;
int acc_y = force_y / mass;
vel_x += acc_x * delta;
vel_y += acc_y * delta;
pos_x += vel_x * delta;
pos_y += vel_y * delta;
}
Thanks
edit: I think this should be in the "I need help (dev stuff only)" section actually but I don't think I can move it now, sorry.