SDL->Surface auschneiden(Scrollen)



  • Nach langen Monaten der GDI bin ich jetzt doch auf SDL umgestiegen
    Nun habe ich ein Problem mit dem scrollen... Das scrollen soll Pixelgenau sein.
    ich habe es schon versucht nur landet bei mir das bild immer oben links, egal wo der chara ist... Hier mal den Code auschnitt:

    void GenerateRandScape(SDL_Surface *from,SDL_Surface *to,SCA_Scape Board[SCAPEX/8][SCAPEY/8],int scx,int scy)
    {
    	SDL_Surface *temp = TDLoadBitmap("tiles.bmp");
    	int sx=0,sy=0;
    	int x=0,y=0;
    	for(x=0;x<SCAPEX;x+=8)
    	{
    		for(y=0;y<SCAPEY;y+=8)
    		{
    			if(y > SCAPEY-200)
    			{
    				TDBlitBitmap(from,temp,x,y,255,48,0,8,8);
    				Board[x/8][y/8].typ = 1;
    				Board[x/8][y/8].layer = 1;
    			}
    			else if(y > SCAPEY-208)
    			{
    				TDBlitBitmap(from,temp,x,y,255,0,0,8,8);
    				Board[x/8][y/8].typ = 7;
    				Board[x/8][y/8].layer = 1; // fest
    			}
    			else Board[x/8][y/8].layer = 0; // fest
    		}
    	}
    	TDBlitBitmap(temp,to,0,0,255,scx,scy,MAXX,MAXY);
    	SDL_FreeSurface(temp);
    }
    
    SDL_Surface *TDLoadBitmap(const char* dir)
    {
    	char strTemp[1024];
    	SDL_Surface *temp,*image;
    	temp = SDL_LoadBMP(dir);
    	if(temp == NULL)
        {
            sprintf(strTemp,"(TDLoadBitmap)Fehler beim Laden vom Bild.\nVerzeichnis:%s\nError: %s",dir,SDL_GetError());
            MessageBox(NULL,strTemp,"Fehler",MB_OK);
    		exit(1);
        }
    	image = SDL_DisplayFormat(temp); // Wandelt das Bild ins Bildschirmformat um und weist die Adresse image zu
    	SDL_FreeSurface(temp); // Die Oberfläche temp wird nun nicht mehr benötigt
    
    	return image;
    }
    
    void TDBlitBitmap(SDL_Surface *from,SDL_Surface *to,int x,int y,int alpha)
    {
    	SDL_Rect rc;
    	rc.x = x;
    	rc.y = y;
    	SDL_SetAlpha(from, SDL_SRCALPHA | SDL_RLEACCEL, alpha);
    	SDL_BlitSurface(from, NULL, to, &rc);
    
    }
    
    inline void TDBlitBitmap(SDL_Surface *from,SDL_Surface *to,int x,int y,int alpha,int x2,int y2,int w,int h)
    {
    	SDL_Rect src, dst;
    	src.x = x2;
    	src.y = y2;
    	src.w = w;
    	src.h = h;
    
    	dst.x = x;
    	dst.y = y;
    	dst.w = w;
    	dst.h = h;
    	SDL_SetAlpha(from, SDL_SRCALPHA | SDL_RLEACCEL, alpha);
    	SDL_BlitSurface(from, &src, to, &dst);
    }
    

    und hier wie ich es aufrufe:

    ...
    SDL_FillRect(screen, &dstblue, SDL_MapRGB(screen->format, 240, 240, 240));
    		TDBlitBitmap(image,screen,tuxX,tuxY,100);
    		GenerateRandScape(tiles,screen,Scape,Player.x,Player.y);
    
    		TDAnimatePlayer(&Player,screen,Scape);
    		TDPlayerKeys(0,&Player);
    		// /Player
    ...
    

    Ich hoffe ihr könnt mir helfen und meine misslungenen versuch verbessern *confused* 😃

    edit: Deutsch verbessert 🙄


Anmelden zum Antworten