【发布时间】:2014-07-13 21:35:39
【问题描述】:
我正在尝试使用此代码在 SDL2 中缩放图像。我希望图像在缩放时保持居中,但我似乎无法弄清楚(我已经尝试了几种方法,这个方法看起来是迄今为止最好的......但这并没有说明太多)
void Image::drawFlat(SDL_Renderer* renderer, int x, int y, float scaleWidth, float scaleHeight) {
if(this->position.x != x || this->position.y != y || this->scaleWidth != scaleWidth || this->scaleHeight != scaleHeight) {
SDL_QueryTexture(this->imageCache, NULL, NULL, &this->position.w, &this->position.h);
this->position.x = (int) x - (this->position.w * scaleWidth + this->position.w) / 2;
this->position.y = (int) y - (this->position.h * scaleHeight + this->position.h) / 2;
this->position.w = (int) this->position.w * scaleWidth;
this->position.h = (int) this->position.h * scaleHeight;
this->scaleWidth = scaleWidth;
this->scaleHeight = scaleHeight;
SDL_RenderCopy(renderer, this->imageCache, NULL, &this->position);
}
}
【问题讨论】:
标签: c++ graphics 2d zooming sdl-2