SDL(简单媒体直接层)试图缩放我的精灵(角色)
SDL (Simple MediaDirect Layer) trying to scale my sprite (character)
我只是想根据窗口的重量和高度来缩放(按比例放大)我的角色。我该怎么做?我尝试了SDL_BlitScaled(newssurface,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曲面,将角色和其他任何对象blit到该曲面,然后最终将该曲面缩放blit到窗口。如果将窗口大小调整为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);
相关文章:
- UE4-如何在给定4个屏幕坐标的情况下缩放纹理或材质
- 计算缩放多边形的比例,得到给定的多边形面积
- QwtPlot具有相等的轴和自动缩放
- 如何在directx/c++中进行平移/缩放操作
- 在Qt中实现无限可缩放的画布
- 是否可以为 QPixmap 派生类嵌入缩放方法?
- 形状对象的旋转和缩放不正确C++
- 如何在 OpenSceneGraph 中缩放/旋转/移动资产
- 如何在OpenGL(GLFW,很高兴)中进行2D缩放?
- 改变或缩放两个正态分布以具有特定的相关系数
- SDL2 调整窗口大小后如何缩放鼠标坐标?
- 如何在OpenGL中正确旋转和缩放对象?
- 仅当类型为 std::complex 时,才进行缩放
- 将 VS Code 用于跨平台可缩放C++项目
- 使用缩放帧的精灵表动画
- SDL(简单媒体直接层)试图缩放我的精灵(角色)
- 在不改变精灵位置的情况下缩放资产
- DirectX精灵在缩放时呈现在不同的位置
- DirectX 9点精灵未缩放
- 在direct3D9中有没有一种方法可以通过最近的邻居来缩放精灵