Page 1 of 1

draw2DImage update rate varies with window size?

Posted: Mon Apr 16, 2007 2:34 am
by khamill
Hi Guys,

I have a rectangle moving across the screen, left to right. Nothing fancy.

When I create my device with a size of 800 X 600 for the window, my rectangle moves across the screen at a reasonable rate.

When I create the device with a size of 1200 X 1000, the rectangle moves across the screen at probably 1/2 to 1/3 the rate compared to when the size was 800 X 600.

Here is the code:

Code: Select all

while(device->run() && driver)
	if (device->isWindowActive())
	{
		driver->beginScene(true, true, video::SColor(255,100,101,140));

      driver->draw2DImage(rect1, core::position2d<s32>(xpos,ypos),
				core::rect<s32>(0,0,256,128), 0, 
				video::SColor(255,255,255,255), true);

      xpos++;

		env->drawAll();

		driver->endScene();
	}
I realize I don't have a method checking the time in the while loop and that may be the problem. I'm just incrementing xpos and using that as my x position.

It's as if my while loop is looping slower while the bigger window...which would increment xpos slower and thus move the rectangle slower across the screen.

BTW, the while loop is being entered on every iteration, I've checked, therefore, xpos is getting incremented on every iteration.

I realize with a bigger wiindow there is more to update which may slow down the while loop, would that be the reason?

Comments?

Posted: Mon Apr 16, 2007 2:37 am
by monkeycracks
I'm pretty tired so this may sound stupid, but maybe it's just that there's more to move across so it only seems slower.

Posted: Mon Apr 16, 2007 3:00 am
by khamill
No, that's not stupid. :D

However, it's also not the solution. I thought of that too. It's real obvious that its slower, but its not an illusion. I don't mean that as a smart remark.

thanks anyways.

Posted: Mon Apr 16, 2007 3:17 am
by Phant0m51
If just display the FPS in the caption bar or somewhere in the window so you can see if there's a difference between the resolutions. If there is (and there probably is) then that's your problem. You should have it update over a specific amount of time, rather than every frame anyway. Consistancy is key.

Posted: Mon Apr 16, 2007 3:45 am
by jam
Just for grins does it move closer to what you want if you change the line

Code: Select all

xpos++;
with

Code: Select all

xpos = xpos + 2;
when your running at 1200 x 1000?

Posted: Mon Apr 16, 2007 4:21 am
by bitplane
velocity = distance / time

there are different numbers of pixels in different sized screens.

or put another way-

Code: Select all

f32 x = xpos / screen_width;
x += speed * time_since_last_loop;
xpos = x * screen_width;

Posted: Tue Apr 17, 2007 12:44 am
by khamill
Fixed.

I should of clued into the fact that 800 X 600 is 480 thousand pixels and 1200 X 1000 is 1200 thousand pixels. Of course the while loops will run at different rates.

I used bitplane's example

Here is my code:

Code: Select all

#define SPEED 0.3

int last_time = timer->getRealTime();

while loop {

int current_time = timer->getRealTime();
		int time_diff = current_time - last_time;
		float x = (float) SPEED * (float) time_diff;

		last_time = current_time;

		xpos += (int) x;

}
Use xpos as I did before in the initial post code above

thanks

Kevin