Re: esc detector wont run -- 'out of scope'
Clangray <[email protected]> Sat, 18 Mar 2017 13:23:07 -0400
| Newsgroups | gmane.comp.lib.sdl |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format.
--===============1749636510019295869==
Content-Transfer-Encoding: 7bit
Content-Type: multipart/alternative; boundary="_----------=_14898577876736900"
This is a multi-part message in MIME format.
--_----------=_14898577876736900
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset="utf-8"
Ok, I introduced a window
#include"SDL.h"
using namespace std;
const char* WINDOW_TITLE = "SDL Start";
int main(int argc, char **argv)
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Window * window = nullptr;
window = SDL_CreateWindow("Hello World!",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
640,480,
SDL_WINDOW_SHOWN);
SDL_Delay(2000); // Delay so that we can see the
SDL_Event event;
cout<<"flag 0";
bool gameRunning = true;
while (gameRunning)
{
cout<<"flag 1"<<endl;
while (SDL_PollEvent(&event))
{
gameRunning = false;
cout<<"flag 2";
if (event.type == SDL_QUIT)
{
cout<<"flag 3";
gameRunning = false;
}
while (event.type == SDL_KEYDOWN)
{
cout<<"flag 2";
SDL_Keycode keyPressed = event.key.keysym.sym;
switch (keyPressed)
{
case SDLK_ESCAPE:
gameRunning = false;
break;
}
}
}
}
SDL_Quit();
cout<<endl<<"end flag";
return 0;
}
I'm getting flag2 constantly.
Esc and other keys seem to have no effect
**if I substitute if for while (below)
change while back to if
if (SDL_PollEvent(&event))
output:
flag 0flag 1
flag 2
end flag
--
Gray Family
[email protected]
On Sat, Mar 18, 2017, at 12:44 PM, Brian Puthuff wrote:
> I agree also. I thought there was some caveat that you needed a window
> open to receive input events.
>
>
> On Mar 18, 2017 9:17 AM, "DLudwig" <[email protected]> wrote:
>> __
>>
>>
>>
>> capehill wrote:
>>
>>
>> Do you have a window open? Does Control-C work?
>>
>>
>>
>>
>> I'd like to second the above.
>>
>> Many platforms need a window open, before input can be received.
>> Using either SDL_CreateWindowAndRenderer, or just SDL_CreateWindow,
>> once beforehand at app init, may be sufficient to fix this.
>>
>> -- David L.
>>
>> _______________________________________________
>> SDL mailing list
>> [email protected]
>> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>>
> _________________________________________________
> SDL mailing list
> [email protected]
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
--_----------=_14898577876736900
Content-Transfer-Encoding: 7bit
Content-Type: text/html; charset="utf-8"
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body><div>Ok, I introduced a window<br></div>
<div><br></div>
<div>#include"SDL.h" <br></div>
<div>using namespace std;<br></div>
<div><br></div>
<div>const char* WINDOW_TITLE = "SDL Start";<br></div>
<div><br></div>
<div>int main(int argc, char **argv)<br></div>
<div>{<br></div>
<div>SDL_Init(SDL_INIT_EVERYTHING);<br></div>
<div><br></div>
<div>SDL_Window * window = nullptr;<br></div>
<div> window = SDL_CreateWindow("Hello World!",<br></div>
<div> SDL_WINDOWPOS_CENTERED,<br></div>
<div> SDL_WINDOWPOS_CENTERED,<br></div>
<div> 640,480,<br></div>
<div> SDL_WINDOW_SHOWN);<br></div>
<div><br></div>
<div> SDL_Delay(2000); // Delay so that we can see the<br></div>
<div><br></div>
<div>SDL_Event event;<br></div>
<div><br></div>
<div>cout<<"flag 0";<br></div>
<div><br></div>
<div> bool gameRunning = true;<br></div>
<div><br></div>
<div> while (gameRunning)<br></div>
<div> {<br></div>
<div> cout<<"flag 1"<<endl;<br></div>
<div> while (SDL_PollEvent(&event))<br></div>
<div> {<br></div>
<div> gameRunning = false;<br></div>
<div> cout<<"flag 2";<br></div>
<div> if (event.type == SDL_QUIT)<br></div>
<div> {<br></div>
<div> cout<<"flag 3";<br></div>
<div> gameRunning = false;<br></div>
<div> }<br></div>
<div><br></div>
<div> while (event.type == SDL_KEYDOWN)<br></div>
<div> {<br></div>
<div> cout<<"flag 2";<br></div>
<div> SDL_Keycode keyPressed = event.key.keysym.sym;<br></div>
<div><br></div>
<div> switch (keyPressed)<br></div>
<div> {<br></div>
<div> case SDLK_ESCAPE:<br></div>
<div> gameRunning = false;<br></div>
<div> break;<br></div>
<div> }<br></div>
<div> }<br></div>
<div><br></div>
<div> }<br></div>
<div><br></div>
<div> }<br></div>
<div><br></div>
<div> SDL_Quit();<br></div>
<div><br></div>
<div> cout<<endl<<"end flag";<br></div>
<div> return 0;<br></div>
<div><br></div>
<div><br></div>
<div><br></div>
<div>}<br></div>
<div><br></div>
<div>I'm getting flag2 constantly.<br></div>
<div>Esc and other keys seem to have no effect</div>
<div><br></div>
<div>**if I substitute if for while (below)<br></div>
<div><br></div>
<div>change while back to if</div>
<div>if (SDL_PollEvent(&event))<br></div>
<div><br></div>
<div>output:<br></div>
<div><br></div>
<div>flag 0flag 1 <br></div>
<div>flag 2<br></div>
<div>end flag<br></div>
<div><br></div>
<div><br></div>
<div id="sig43414442"><div class="signature">--<br></div>
<div class="signature"> Gray Family<br></div>
<div class="signature"> [email protected]<br></div>
<div class="signature"><br></div>
</div>
<div><br></div>
<div><br></div>
<div>On Sat, Mar 18, 2017, at 12:44 PM, Brian Puthuff wrote:<br></div>
<blockquote type="cite"><div><div>I agree also. I thought there was some caveat that you needed a window open to receive input events.<br></div>
<div><div><br></div>
<div><div><br></div>
<div defang_data-gmailquote="yes"><div>On Mar 18, 2017 9:17 AM, "DLudwig" <<a href="mailto:[email protected]">[email protected]</a>> wrote:<br></div>
<blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204, 204, 204);padding-left:1ex;"><div><u></u><br></div>
<div><div><div align="center"><div><br></div>
<div><br></div>
<table width="90%" align="center" cellspacing="1" cellpadding="2" border="0"><tbody><tr><td><br></td></tr><tr><td align="left">capehill wrote:<br></td><td><br></td></tr><tr><td><br></td></tr><tr><td align="left">Do you have a window open? Does Control-C work?<br></td><td><br></td></tr><tr><td><br></td></tr></tbody></table></div>
<div><br></div>
<div><br></div>
<div>I'd like to second the above.<br></div>
<div> <br></div>
<div> Many platforms need a window open, before input can be received. Using either SDL_CreateWindowAndRenderer, or just SDL_CreateWindow, once beforehand at app init, may be sufficient to fix this.<br></div>
<div> <br></div>
<div> -- David L.<br></div>
</div>
</div>
<div><br></div>
<div>______________________________<wbr>_________________<br></div>
<div> SDL mailing list<br></div>
<div> <a href="mailto:[email protected]">[email protected]</a><br></div>
<div> <a href="http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org">http://lists.libsdl.org/listin<wbr>fo.cgi/sdl-libsdl.org</a><br></div>
<div> <br></div>
</blockquote></div>
</div>
</div>
</div>
<div><u>_______________________________________________</u><br></div>
<div>SDL mailing list<br></div>
<div><a href="mailto:[email protected]">[email protected]</a><br></div>
<div><a href="http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org">http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org</a><br></div>
</blockquote><div><br></div>
</body>
</html>
--_----------=_14898577876736900--
--===============1749636510019295869==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
SDL mailing list
[email protected]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
--===============1749636510019295869==--