Dobrý den, mám problém, podle návody jsem si udělal pohyblivý obrázek ale chtěl sem pod něj background aby obrázek nedělal čmouhy. Plocha se ale vykresluje jen při pohybu doleva a nahoru viz. screen.
Kod main
#include <iostream>
#include "SDL.h"
#include "hlavicka.h"
int main(int argc, char *argv[])
{
if( SDL_Init(SDL_INIT_VIDEO) < 0 ){
printf("Inicializace SDL se nezdařila: %s\n", SDL_GetError());
exit(1);
}
atexit(SDL_Quit);
screen = SDL_SetVideoMode(800, 600, 32, SDL_HWSURFACE|SDL_DOUBLEBUF);
SDL_SWSURFACE;
if ( screen == NULL ){
printf("Vytvoření okna se nezdařilo: %s\n", SDL_GetError());
exit(1);
}
LoadImage();
DrawIMG(background, 0, 0);
bool done=false;
while (done == false)
{
SDL_Event event;
while( SDL_PollEvent(&event) )
{
if( event.type == SDL_QUIT ) done=true;
if(event.type == SDL_KEYUP){
if(event.key.keysym.sym == SDLK_ESCAPE) done = true;
}
}
keys = SDL_GetKeyState(NULL);
if(keys[SDLK_RIGHT]) image_x += 1;
if(keys[SDLK_LEFT]) image_x -= 1;
if(keys[SDLK_DOWN]) image_y += 1;
if(keys[SDLK_UP]) image_y -= 1;
DrawScene2(screen);
};
return 0;
}
kod hlavicka.h
#ifndef _HLAVICKA_H
#define _HLAVICKA_H
SDL_Surface *screen;
SDL_Surface *image;
SDL_Surface *background;
Uint8* keys;
int image_x,image_y;
void LoadImage()
{
image = SDL_LoadBMP("image.bmp");
background = SDL_LoadBMP("bg.bmp");
}
void DrawIMG(SDL_Surface *img, int x, int y){
SDL_Rect rect;
rect.x = x;
rect.y = y;
SDL_BlitSurface(img, NULL, screen, &rect);
}
void DrawIMG_2(SDL_Surface *img, int x, int y, int w, int h,int x2, int y2){
SDL_Rect rect;
rect.x = x;
rect.y = y;
SDL_Rect rect2;
rect2.x = x2;
rect2.y = y2;
rect2.w = w;
rect2.h = h;
SDL_BlitSurface(img, &rect2, screen, &rect);
}
void DrawScene2(SDL_Surface *screen){
DrawIMG(image, image_x, image_y);
DrawIMG_2(background, image_x-1, image_y-1, 152, 152,image_x-1, image_y-1);
SDL_Flip(screen);
}
#endif
Předem děkuji za odpověď