Easy question about mouse click

Started by
6 comments, last by izzo 19 years, 4 months ago
I am trying to make my splash screen go away with a mouse click like this. case WM_LBUTTONDOWN: { first.show = false; return 0; } but it does not work. if (first.show == true) { // Draw the background to the screen. r.left = 0; r.top = 0; r.right = 800; r.bottom = 600; RECT dstr; dstr.left =first.splashx; dstr.top = first.splashy; dstr.right = first.splashx + r.right; dstr.bottom = first.splashy + r.bottom; lpBackBuffer->Blt(&dstr,lpA,&r,DDBLT_WAIT,NULL); /* lpBackBuffer->BltFast(0, 0, lpA, &r, DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT); */ Flip(); wait (4); }
Advertisement
Well, I don't use directx, but if Flip is the command that flips the buffers - have you got a redraw and Flip command outside of this loop (ie when first.show == false)? If you don't, it will never update the front-buffer.

Just a guess!
Jim.
Just as a general rule, it's almost always a better idea to trap and operate on the button release than it is to operate on the button press. Lots of little weird problems are avoided by doing this. And it gives the user the chance for an OOPS moment...like when you click the cancel button and, rather than lose what you have, you just slide the cursor off the button and then release.

Good luck.
I think it has something to do with my wait function but I cant figure how else to hve the slpash screen be displayed and click on it to go away and if there is no click it just waits for 4 seconds. any one know how to do this correctly?
Just make a timer, my friend. =) I think the windows function is GetTickCount, which returns a DWORD which is the number of milliseconds since the system started up. (It doesnt' repeat for almost a full month, so don't worry about that. This is true for all modern windows systems.)

SO when you start your timer, grab the tick count and stick it in DWORD dwTheTimeWeStarted. Then every iteration, check GetTickCount against dwTheTimeWeStarted. If 4000 milliseconds (i.e. four seconds) have elapsed (that is, dwTheTimeWeStarted >= GetTickCount() + 4000) well, terminate. If you want to have a mouse click do it to, just add the ifMouseClick bool to your loop termination expression.

Good luck.
Ok let me try this again. I don’t think I asked my question correctly. Witch is usually the deal.

So I get my splash screen to dispaly for 4 seconds and now I want it to disapear when pressing the left mouse button.

THe way I would make a splash screen would be split my game loop with several states.

Like:
SplashScreen = 1
SplashScreenFade = 2
MainMenu = 3
etc, etc...

Then, when in your game loop you have your switch (or select, I keep mixing those 2 up).

When you start your game you set the state to 1.
Then as long as the state is 1 it will draw your splash screen.
Then as soon as the timer says your done you set the state to 2 and do your splash screen fade routine (if any).
Or if you have pressed your mouse button.

Well, that's how I would do it.
So you want your splash screen to appear for either four seconds, or if the user presses the mouse button (whichever happens first) right?

You probably don't want to call wait down there. That's going to pause execution of the thread and you won't be able to process your mouse clicks. You should do what serratemplar suggested: use GetTickCount. This way you can keep checking for mouse clicks. Check the elapsed time since the splash screen was first started and if 4 seconds have passed set first.show to false.

btw serratemplar, good tip on the mouse release!

cheers
sam

This topic is closed to new replies.

Advertisement