我只是想根据窗口的重量和高度来缩放(按比例变大)我的角色。我怎样才能做到这一点? 我尝试了 SDL_BlitScaled(newsurface, NULL, screen, NULL);但它不起作用。 我的代码:
SDL_Surface* screen = SDL_GetWindowSurface(win);
SDL_Surface* mySprite = IMG_Load( SPRITE_PNG_PATH);
SDL_Rect rcSprite;
rcSprite.x = 250;
rcSprite.y = 100;
SDL_BlitSurface(mySprite, NULL, screen, &rcSprite);
最佳答案
实现此目的的最佳方法是拥有一个中间表面,其宽度和高度是游戏的原始分辨率。然后,您将整个帧渲染到该表面,并使用 SDL_BlitScaled
函数将该表面渲染到窗口。
例如,如果您希望原始分辨率为 600x400,则可以创建一个 600x400 表面,将角色和其他任何内容传输到该表面,然后最终将该表面缩放到窗口。如果将窗口大小调整为 1200x800,所有内容看起来都会大两倍。
SDL_Surface* screen = SDL_GetWindowSurface(win);
// Create a surface with our native resolution
int NATIVE_WIDTH = 600;
int NATIVE_HEIGHT = 400;
SDL_Surface* frame = SDL_CreateRGBSurface(0, NATIVE_WIDTH, NATIVE_HEIGHT,
screen->format->BitsPerPixel, screen->format->Rmask,
screen->format->Gmask, screen->format->Bmask, screen->format->Amask);
assert(frameSurface);
SDL_Surface* mySprite = IMG_Load( SPRITE_PNG_PATH);
SDL_Rect rcSprite;
rcSprite.x = 250;
rcSprite.y = 100;
// Blit everything to the intermediate surface, instead of the screen.
SDL_BlitSurface(mySprite, NULL, frame, &rcSprite);
// Once we've drawn the entire frame, we blit the intermediate surface to
// the window, using BlitScaled to ensure it gets scaled to fit the window.
SDL_BlitScaled(frame, NULL, screen, NULL);
关于c++ - SDL(简单媒体直接层)尝试缩放我的 Sprite (角色),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25860443/