Jump to content
  • Advertisement
Sign in to follow this  
ICUP

Updating Screen Question

This topic is 3756 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

if ( mEvent.type == SDL_MOUSEMOTION )
			{
				SDL_GetMouseState( &x, &y );

				if ( ( x > imageRect[ 0 ].x ) && ( x < imageRect[ 0 ].x + imageRect[ 0 ].w ) 
				  && ( y > imageRect[ 0 ].y ) && ( y < imageRect[ 0 ].y + imageRect[ 0 ].h ) )
				{
					menu.BlitMouseOverButton( SBBLUE );
					menu.DisplayMenu();
				}

				else if ( ( x > imageRect[ 1 ].x ) && ( x < imageRect[ 1 ].x + imageRect[ 1 ].w ) 
				       && ( y > imageRect[ 1 ].y ) && ( y < imageRect[ 1 ].y + imageRect[ 1 ].h ) )
				{
					menu.BlitMouseOverButton( ABYELLOW );
				}
				
				else if ( ( x > imageRect[ 2 ].x ) && ( x < imageRect[ 2 ].x + imageRect[ 2 ].w ) 
				       && ( y > imageRect[ 2 ].y ) && ( y < imageRect[ 2 ].y + imageRect[ 2 ].h ) )
				{
					menu.BlitMouseOverButton( QBRED );
				}
				else
					menu.DisplayMenu();
			}





In the code above, when the mouse is continually over the button, it continually blits the button. When the mouse is off the button it continuously blits the menu. Is this bad? I'm guessing it is because in the background it's making function calls repeatedly non-stop. I thought I read somewhere that the screen should only be updated when something changes. Even though my mouse isn't moving, I know that it is continuously blitting the images. [Edited by - ICUP on June 10, 2008 4:19:30 AM]

Share this post


Link to post
Share on other sites
Advertisement
SDL_MOUSEMOTION will only occur if the mouse moves. So everything is only blitted when the mouse is being moved.

You can limit the drawings like this:

When a mouse goes in or out (so not when it's just ON the button, it must make a transition between being ON and OFF the button), you update the button.
And I don't think you need to update the menu. Is the menu drawing the buttons too? And has the menu no changing things at all? Don't redraw it when a SDL_MOUSEMOTION occurs.

To make it more easy, I always update the screen whenever an events occurs. And in games it actually changes every frame, so checking if things have changed is overhead in that case, and it should update it just every frame. For GUI's you can limit it yes.

Games like Call of Duty 4 put a maximal FPS of 20 or 30 on menu's. They don't even check if things have changed. And HUD (GUI ingame) needs to be drawn on top every frame, so that has to be updated aswell.

Share this post


Link to post
Share on other sites
See, here's the weird thing though. Those if statements are to be tested ONLY if the mouse moves. The thing is, the mouse ISN'T moving. I can have the mouse be still and I know that it is still testing those statements. I know because when I move my mouse over the button, it flashes the two different colors (one for mouse over, and one for when it isn't. To test this I placed the DisplayMenu function after it blits one of the buttons) even if the mouse isn't moving.

I wonder if this has anything to do with the mouse itself? Are optical mouses always moving? Those red lights searching for movement?

Share this post


Link to post
Share on other sites
I think I got it. I switched from SDL_PollEvent to SDL_WaitEvent. I guess PollEvent is always looking for something to do.

Share this post


Link to post
Share on other sites
Can someone give me a method in pseudocode or code where to test whether the mouse is ON and OFF the button?

Share this post


Link to post
Share on other sites
SDL_Event event;
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_MOUSEMOTION:
{
break; // mouse moves
}
case SDL_MOUSEBUTTONDOWN:
{
break; // mouse button clicked
}
}
}

// and to see if something is inside a box:

struct Field
{
int x, y, w, h;
Field() : x(0), y(0), w(0), h(0) {}
Field(int x, int y, int w, int h) : x(x), y(y), w(w), h(h) {}
};

bool in_field(int x, int y)
{
if (x >= field.x && (!field.w || x < (field.x + field.w)) && y >= field.y && (!field.h || y < (field.y + field.h)))
{
return true;
}
return false;
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!