c++ - Surface dissapears when I use SDL_RECT -
im trying create class contains info of game's ship (image , position @ moment), compiles expected if use sdl_rect variable created inside ship argument in sdl_blitsurface method, ship not appear.
here's code:
main.cpp
int main() { init(); ship ship; ship.alive(); background bg; sdl_blitsurface(bg.bg,null,screen,null); printf("%i",ship.rect.y); sdl_blitsurface(ship.img,&ship.rect,screen,null); sdl_updatewindowsurface(window); sdl_delay(5000); return 0; }
ship.cpp
ship::ship(){ std::string path = "img/arwing2.png"; x = 50; y = 50; rect.x = x; rect.y = y; rect.w = 300; rect.y = 300; img = img_load(path.c_str()); if(img == null){ printf("unable load image"); } printf("hey!!"); } void ship::alive(){ printf("i'm alive!"); }
any idea of i'm doing wrong? want
this get
in code, have provided source rect.
this means cutting image show pixels (x,y) inside image , extending (w,h).
what wanted provide destination rect tell sdl_blitsurface draw it, i.e. (x,y) inside screen. follows:
sdl_blitsurface(ship.img, null, screen, &ship.rect); ^(src) ^(dest)
Comments
Post a Comment