draw2DImage update rate varies with window size?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
khamill
Posts: 17
Joined: Thu Mar 08, 2007 3:50 pm
Location: Nova Scotia, Canada

draw2DImage update rate varies with window size?

Post 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?
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Post 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.
khamill
Posts: 17
Joined: Thu Mar 08, 2007 3:50 pm
Location: Nova Scotia, Canada

Post 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.
Phant0m51
Posts: 106
Joined: Mon Jan 15, 2007 6:07 am

Post 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.
jam
Posts: 409
Joined: Fri Nov 04, 2005 3:52 am

Post 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?
system-independent, adj.:
Works equally poorly on all systems.
-- unknown
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post 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;
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
khamill
Posts: 17
Joined: Thu Mar 08, 2007 3:50 pm
Location: Nova Scotia, Canada

Post 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
Post Reply