Now I am trying to get the image to just move off center a little bit by using differant x and y values. But when I run this program the image move off screen in increments. Ironically this is the effect I wanted but, I didn't think I was ready so i was just trying to move image a little bit off center not have it keep moving. So here is my code the problem is that the images keeps moving rather than just blitting onto the screen a bit off center. Not any where in the code do I modify xpos or ypos, that I can tell, so I Dont see why when ever I redraw the screen the image moves.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include "SDL.h"
using namespace std;
SDL_Surface *scrn1, *back;
int misc;
int xpos=2;
int ypos=1;
int InitSDL();
int Setscreenvidmode();
int Blitscreen(SDL_Surface *scrn, SDL_Surface *scrnn);
int SwitchLoadImg(SDL_Surface *scrn,int imgnum);
int main(int argc, char*argv[]){
int imgnum=1,done=0;
InitSDL();
atexit(SDL_Quit);
Setscreenvidmode();
SwitchLoadImg(scrn1,imgnum);
while(done == 0)
{
Blitscreen(scrn1,back);
if (imgnum>4){imgnum=1;}
SDL_Event event;
while ( SDL_PollEvent(&event) )
{
if ( event.type == SDL_QUIT ) { done = 1; }
if ( event.type == SDL_KEYDOWN )
{
if ( event.key.keysym.sym == SDLK_ESCAPE ) { done = 1; }
if ( event.key.keysym.sym == SDLK_n) {SwitchLoadImg(scrn1,++imgnum);}
}
}
}}//////////////////////////////////////////END OF MAIN//////////////////////
int InitSDL() {
if ((SDL_Init(SDL_INIT_VIDEO||SDL_INIT_AUDIO))<0){
cout<<SDL_GetError();
}
};
int Setscreenvidmode(){
scrn1 = SDL_SetVideoMode(500,380,32,SDL_SWSURFACE||SDL_DOUBLEBUF);
back = SDL_SetVideoMode(500,380,32,SDL_SWSURFACE||SDL_DOUBLEBUF);
};
int Blitscreen(SDL_Surface *scrnn, SDL_Surface *scrn){
SDL_Rect trect;
trect.x=xpos;
trect.y=ypos;
SDL_BlitSurface(scrnn,NULL,scrn,&trect);
SDL_Flip(scrn);
};
int SwitchLoadImg(SDL_Surface *scrn,int imgnum){
SDL_Surface *temp;
switch (imgnum){
case 1:
temp = SDL_LoadBMP("Pic1.bmp");
break;
case 2:
temp = SDL_LoadBMP("Pic2.bmp");
break;
case 3:
temp = SDL_LoadBMP("Pic3.bmp");
break;
case 4:
temp = SDL_LoadBMP("Pic4.bmp");
break;
default:
temp = SDL_LoadBMP("Pic1.bmp");
break;
}
SDL_BlitSurface(temp,NULL,scrn,NULL);
};