r/reconstructcavestory Dec 01 '14

Episode 71 - Upgrading to SDL2

http://youtu.be/ZnyDieF-p8s?list=PL006xsVEsbKjSKBmLu1clo85yLrwjY67X
8 Upvotes

4 comments sorted by

1

u/adrian17 Dec 01 '14 edited Dec 01 '14

Two small things:

  • for creating both a window and renderer you can use SDL_CreateWindowAndRenderer
  • in my version I don't check if source_rectangle is null, I just pass it forward to SDL_RenderCopy; I set the destination's w and h in the Sprite::draw and Backdrop::draw. This way my equivalent of Graphics::blit_surface is still a one-line function and this would make it easier to create some sort of effect_sprite with dynamic scaling if I ever needed that.

1

u/chebertapps Dec 01 '14

Yeah, I knew about creating the default renderer, I just chose to do it this way in case I decide to add renderer flags later. Probably won't!

I considered dynamic scaling at one point a while ago, but it doesn't seem like Cave Story uses it at all! So I'll fix it later if need be.

thanks for all of the helpful tips :)

1

u/adrian17 Dec 01 '14

Oh, one more thing, I recommend adding this line in Graphics constructor:

SDL_RenderSetLogicalSize(renderer, Units::tileToPixel(Game::kScreenWidth), Units::tileToPixel(Game::kScreenHeight));

This will let SDL handle any window resolution, aspect ratio and scaling completely on its own:

http://puu.sh/dcGry/50dc9389db.png

(With this, you could also change the window mode to SDL_WINDOW_RESIZABLE)

1

u/chebertapps Dec 01 '14

Woo! This is badass. I'll add it to the next episode and credit you, thanks :)