Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 07 Aug 2012
Offline Last Active Aug 15 2012 03:37 AM

Posts I've Made

In Topic: Problems with SDL Input

07 August 2012 - 09:06 PM

Well thank you very much for that tip on the SDL_EnableKeyRepeat. Here's that player::show() function. See anything strange?

[source lang="cpp"]void Player::Show() { character = LoadImage(direction); Blit(x, y, character, screen); }[/source]

In Topic: Problems with SDL Input

07 August 2012 - 05:27 PM

I have made it to where it only polls once and just passes the event along. However, the input still isn't continuous and in fact it has some weird effect where when one key is pressed, instead of moving the character a continuous amount of units in that certain direction, it goes 5 units in the direction while the key is down and goes 5 again when the key is up. And also, I figure it may be a memory leak caused by maybe pointers or something, however, after a quick glance, it doesn't appear that anything funky is being done with pointers. I would show more code, however, not knowing where the problem may be, I'm not sure what portion of the code to show. However, these are the image functions which use more pointers than any other part:

[source lang="cpp"]SDL_Surface * LoadImage(std::string path) { SDL_Surface * loadedImage = NULL; SDL_Surface * optimizedImage = NULL; loadedImage = IMG_Load( path.c_str() ); if(loadedImage != NULL) { optimizedImage = SDL_DisplayFormat(loadedImage); SDL_FreeSurface(loadedImage); if(optimizedImage != NULL) { Uint32 colorkey = SDL_MapRGB(optimizedImage->format, 111, 111, 111); SDL_SetColorKey(optimizedImage, SDL_SRCCOLORKEY, colorkey); } } return optimizedImage; }void Blit(int x, int y, SDL_Surface* source, SDL_Surface* destination) { Rect coords; coords.x = x; coords.y = y; SDL_BlitSurface( source, NULL, destination, &coords ); }void ColorRect(SDL_Surface* surface, int x, int y, int z) { SDL_FillRect(surface, 0, SDL_MapRGB(surface->format, x, y, z)); }void Update(SDL_Surface* surface) { SDL_Flip(surface); }[/source]

In Topic: Problems with SDL Input

07 August 2012 - 04:02 PM

Ah, well this is very strange. Polling the event inside the function or outside the function provides no differences and the program still continuously amasses a large quantity of memory it doesn't need. I'm not sure why this program works perfectly when everything's in the same source file and yet it starts acting funky when classes and multiple source files are involved.