   Im MAD do to problem I cant fix!!!!
  I have been post this problem and asking people by pm, with help that made more code a bit better but did not fix the problem.In SDL I load a image to the screen, when I tell the image to change it does not!!!Been on it for a week with no success...Ex:loadSprite();//Loads 2 images and puts them in sprite1 and sprite2.output = something;//this is out of the main loop so it will just give output some image one timewhile(handeInput)//loop that checks if any key has been pressedshow(x,y,output,screen);//in loopflip(screen)//in loopIn handeInput I have it load another image when the downkey is pressed too see if I can change output. I simple put output = sprite2;I know it works since the sprite moves down when I hit the down key but output never changes...For some reson it wont change. If I try to free output too see if I release the image it was holding so it can load a new one, I get access violations.I just want to know why output even when it is being assigned to something else remains the same.   
  Are you maybe assigning something that's been passed by value rather then by reference? It's hard to say unless we see the actual assignment code in your handleInput function.   ;  There is not a chance in hell anyone is going to be able to help you if you post code like that. It is the equivalent of me posting:Quote:my uber l33t OS isn't booting; can anyone see a problem?code:startOS();if would be best if you used the source tags ["source]["/source"] (without quotes!) to post relevant portions of your code like thus:int* p = new int;p=35;int* q=p;*q = 42; //uhoh! segfault here...why???Try posting the sections of code where you load the sprites, how you change them, etc. Then people can potentially see errors in your code.   ;  Sorry just that I have posted my code in another topic and thought it might considered spam if I just kept on reposting it.Code has changed since I posted last comment...mainly in Events.cpp under SDLK_1 I put v.output=v.sprite2;main#include "Global.h"#include "Video.h"#include "Events.h"int main(int argc,char* args[]){Events e;Video v;SDL_Init(SDL_INIT_EVERYTHING);v.st();//only use for this is to post basic windowv.LoadSprite(); //loads different spritese.num=0;v.output=v.loadImg("1.bmp");while(e.handleInput())//Main loop{v.check();e.num+=1;v.show(e.x,e.y,v.output,v.screen);//displays sprite to screenv.flip(v.screen);//refreshes screen}SDL_FreeSurface(v.sprite);SDL_FreeSurface(v.sprite2);return 0;}Video.cpp#include "Global.h"#include "Video.h"Video::Video(){}void Video::show(int x,int y,SDL_Surface *s,SDL_Surface *d)//All images will be displayed with this{SDL_Rect offset;offset.x = x;offset.y = y;SDL_FillRect(screen,&screen->clip_rect,SDL_MapRGB(screen->format,0,0,0));//fills screen backgroundSDL_BlitSurface(s,NULL,d,&offset);}SDL_Surface *Video::loadImg(std::string filename){SDL_Surface* temp = SDL_LoadBMP(filename.c_str());if(temp==NULL){return false;}SDL_Surface* out = SDL_DisplayFormat(temp);SDL_FreeSurface(temp);Uint32 colorkey = SDL_MapRGB(out->format,255,255,255);//makes everything on image that is whiteSDL_SetColorKey(out,SDL_SRCCOLORKEY,colorkey);//transparentreturn out;}void Video::flip(SDL_Surface *file){SDL_Flip(file);}void Video::st(){screen = SDL_SetVideoMode(800,600,24,SDL_SWSURFACE);} void Video::LoadSprite(){sprite = loadImg("1.bmp");sprite2 = loadImg("2.bmp");}SDL_Surface *Video::check() { Events e; if(e.num==0) { output = sprite; } else if(e.num>=1) { output = sprite2; } else if(e.num<0) {output = sprite; } return output; } Video.h#ifndef _VIDEO_H_#define _VIDEO_H_#include "Global.h"#include "Events.h"class Video{private:public:SDL_Surface *sprite;SDL_Surface *sprite2;SDL_Surface *screen;SDL_Surface *output;int num;Video();void st();void show(int x,int y,SDL_Surface *s,SDL_Surface *d);SDL_Surface *loadImg(std::string filename);void flip(SDL_Surface *file);void LoadSprite();SDL_Surface *check();};#endifEvents.h#ifndef _EVENTS_H_#define _EVENTS_H_#include "Global.h"#include "Video.h"class Events{private:public:int x,y;//Do to problems movement of sprite has to be in eventsint num;Events();bool handleInput();//Handles movement};#endifEvents.cpp#include "Global.h"#include "Events.h"Events::Events(){y=0;x=0;}bool Events::handleInput(){SDL_Event event;Video v;while(SDL_PollEvent(&event)){if(event.type == SDL_QUIT){return false;}if(event.type == SDL_KEYDOWN){switch(event.key.keysym.sym){case SDLK_UP:y-=tileH;break;case SDLK_DOWN:y+=tileH;break;case SDLK_RIGHT:x+=tileW;break;case SDLK_LEFT:x-=tileW;break;case SDLK_1:num+=1;break;case SDLK_2:num-=1;break;}}}return true;};  Well, for one. Don't use a LoadSprite() function. It's not needed. All you need to do is like the following...main.cpp#include <SDL/SDL.h>#include <string>#include "sprite.h"int main(int argc, char* argv[]){Init();LoadFiles();while(GameLoop){ SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));Draw(SpriteX, SpriteY, Sprite, Screen);HandleInput();SDL_Flip(screen);}CleanUp();return 0;}sprite.h#include <SDL/SDL.h>#include <string>int SpriteX = 0;int SpriteY = 0;SDL_Event event;bool GameLoop = true;SDL_Surface *screen = NULL;SDL_Surface *sprite = NULL;SDL_Surface *sprite_moving_right = NULL;SDL_Surface *sprite_moving_left = NULL;void Draw(int x, int y, SDL_Surface *src, SDL_Surface *dst){SDL_Rect offset;offset.x = x;offset.y = y;SDL_BlitSurface(src, NULL, dst, &offset);}void HandleInput(){SDL_PollEvent(&event);if(event.type == SDL_KEYDOWN){switch(event.key.keysym.sym) {case SDLK_LEFT:sprite = sprite_moving_left;break;case SDLK_RIGHT:sprite = sprite_moving_right;break;}}if(event.type == SDL_QUIT){GameLoop = false;}}bool Init(){if(SDL_Init(SDL_INIT_EVERYTHING) < 0){return false;}screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);if(!screen){return false;}SDL_WM_SetCaption("Sprite Test", NULL);return true;}bool LoadFiles(){sprite_moving_right = SDL_LoadBMP("1.bmp");sprite_moving_left = SDL_LoadBMP("2.bmp");sprite = sprite_moving_right;}I haven't compiled this myself, but it should help you if you really look at the code. The sprite surface is a pointer to the other two surfaces, when you change direction, your change your pointer to point at that image under that surface and then draw it onto the screen   ;  After a LOT of testing I got some results.while(e.handleInput())//Main loop{v.check();if(i>200){v.number=1;}i++;v.show(e.x,e.y,v.output,v.screen);//displays sprite to screenv.flip(v.screen);//refreshes screen}v.check checks too see if number is 1. If so then it post the second sprite. If number is posted in or out of the main loop sprite changes on load. When in the if loop sprite changes when i is greater than 200. But if number is given 1 in e.handleInput nothing happens. For some reason it wont work with it. When I put a event handler in my main loop too post number 1 when any key is pressesd I get nothing. Now I need to find out why it wont work with events. Any ideas?   ;  That's because your loop isn't really a loop. You cannot put a function into a while loop. You need to make boolean. Change it to something like this:bool ProgramRunning = true; // Main loopwhile(ProgramRunning)//Main loop{ e.handleInput()v.check();if(i>200){v.number=1;}i++;v.show(e.x,e.y,v.output,v.screen);//displays sprite to screenv.flip(v.screen);//refreshes screen};  Just a slight comment, you really really should give your variables real names, e v etc are no good   ;Quote:Original post by noobletThat's because your loop isn't really a loop. You cannot put a function into a while loop.What? Of course you can!;Quote:Original post by noobletThat's because your loop isn't really a loop. You cannot put a function into a while loop. You need to make boolean. Change it to something like this:*** Source Snippet Removed ***Eh? His code was valid. Have you never seen this kind of thing before:bool CEngine::AmIRunning(){  return m_Running;}...while(Engine->AmIRunning()){  //Do something funky}?