Trouble With Sdl Events


YenningComity

Still Fresh
Joined
Sep 19, 2005
Messages
12
I have been fooling around with the following piece of code, but am failing to get it to exit a simple loop. I know my input works correctly because I can reassign quit to any input, and it works flawlessly. However, I am unable to increment credits.

CODE
include "input.h"

void attractInput(bool& quit, int& credits, bool& start, SDL_Event& event){

while(SDL_PollEvent(&event)){
//If a key was pressed
if(event.type == SDL_KEYDOWN){
switch(event.key.keysym.sym){
case SDLK_ESCAPE: quit = true;
break;
case SDLK_1: credits += 1;
break;
case SDLK_RETURN: start = true;
break;
}
}
}
}


CODE
void attractOn(bool& quit, int& credits){
SDL_Event event;

//Is True when Player Hits Start Button
bool checkForStart = false;

string backgroundFile = "attractTest.png";

//Load The Background
if(loadBackground(backgroundFile)==false){
return;
}//if(swapBuffers()==false)

while (quit == false){
//Get Player Input
attractInput(quit, credits, checkForStart, event);

//Check Starting Conditions
if(checkForStart == true){
if(credits > 0){
credits -= 1;

//Clear Images
cleanUp();

return;
}
}
//Clear Images
cleanUp();

return;
}//void attractMode()
 
what are credits defined as, the original declaration isnt in your code here. Are you initializing credits to 0?
Can you run a debug like gdb or something similar, should point at the problem fairly quickly.
 
Nevermind, I seem to have gotten it running. The only trouble is I am not sure what i did ...
 
Back
Top