Creating an update function for my game
-
I was told that if I want to call invalidate rectangle the space between begin paint and end paint is not a good place to set the dimensions of rectangles, hence I`m trying to create an update function for my game, a place where I can set the position and dimension of rectangles and also compute all sorts of other things required in the game. I borrowed this code from a DirectX tutorial
while (WM_QUIT != msg.message)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);} else { UpdateGame(); }
}
but the execution never reaches UpdateGame(). Could you please help me out find a place for UpdateGame()?
-
I was told that if I want to call invalidate rectangle the space between begin paint and end paint is not a good place to set the dimensions of rectangles, hence I`m trying to create an update function for my game, a place where I can set the position and dimension of rectangles and also compute all sorts of other things required in the game. I borrowed this code from a DirectX tutorial
while (WM_QUIT != msg.message)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);} else { UpdateGame(); }
}
but the execution never reaches UpdateGame(). Could you please help me out find a place for UpdateGame()?
You need to provide more details about what you are trying to do here. Calling
UpdateGame
in the message loop as you show, will only work if there are no messages in the queue. And given the way Windows operates, this is not very likely. The only thing you should do in yourWM_PAINT
handler, is to update the screen. All calculations and measurements should be performed elsewhere. -
I was told that if I want to call invalidate rectangle the space between begin paint and end paint is not a good place to set the dimensions of rectangles, hence I`m trying to create an update function for my game, a place where I can set the position and dimension of rectangles and also compute all sorts of other things required in the game. I borrowed this code from a DirectX tutorial
while (WM_QUIT != msg.message)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);} else { UpdateGame(); }
}
but the execution never reaches UpdateGame(). Could you please help me out find a place for UpdateGame()?
Quote:
but the execution never reaches UpdateGame()
Are you sure? Even here: The basic game loop · microsoft/DirectXTK12 Wiki · GitHub[^] such a loop is suggested (look at the bottom of the page).
"In testa che avete, Signor di Ceprano?" -- Rigoletto
-
You need to provide more details about what you are trying to do here. Calling
UpdateGame
in the message loop as you show, will only work if there are no messages in the queue. And given the way Windows operates, this is not very likely. The only thing you should do in yourWM_PAINT
handler, is to update the screen. All calculations and measurements should be performed elsewhere.Original post edited, I hope it makes sense now
-
Original post edited, I hope it makes sense now
-
I just ran a quick test and the call to
UpdateGame
does indeed get called many times in a simple Window. You need to do some more debugging to find out why that does not happen in your code. -
Wow, you're a game developer, now! :thumbsup: :-D
"In testa che avete, Signor di Ceprano?" -- Rigoletto