C++ SDL(C+;+;)中的动画不正确?

C++ SDL(C+;+;)中的动画不正确?,c++,animation,sdl,render,sdl-2,C++,Animation,Sdl,Render,Sdl 2,我正在尝试使用SDL(c++)为图片(320宽,64高)生成一个动画,每帧64×64 我的问题是,我的整个图片(320×64)被压缩在64×64的空间中,而不是每帧显示 我有一个AnimatedSprite类,用于使用Draw()方法绘制动画 DrawAnimatedSprite的方法如下: void BackBuffer::DrawAnimatedSprite(AnimatedSprite& animatedSprite) { SDL_Rect fillRect; fillRect.x

我正在尝试使用SDL(c++)为图片(320宽,64高)生成一个动画,每帧64×64

我的问题是,我的整个图片(320×64)被压缩在64×64的空间中,而不是每帧显示

我有一个AnimatedSprite类,用于使用Draw()方法绘制动画

DrawAnimatedSprite的方法如下:

void BackBuffer::DrawAnimatedSprite(AnimatedSprite& animatedSprite)
{
SDL_Rect fillRect;
fillRect.x = animatedSprite.GetX();
fillRect.y = animatedSprite.GetY();
fillRect.w = animatedSprite.getFrameWidth();
fillRect.h = animatedSprite.GetHeight();
SDL_RenderCopy(m_pRenderer, animatedSprite.GetTexture()->GetTexture(), 0, &fillRect);
}
有人知道哪里错了吗? 谢谢


您正在将
fillRect
传递到
dstrect
,而不是
srrect
问题确实在于您使用的方式,但您也应该提供srrect和dstrect,一个是您希望在其中渲染图像的目标,另一个是您希望在其中渲染纹理的哪一部分

例如,如果精灵图纸为(320×64),精灵大小为(64x64),并且希望在屏幕上的fillRect坐标(x,y)处打印第一帧,则应执行以下操作:

SDL_Rect clip;
clip.x = 0;
clip.y = 0;
clip.w = 64;
clip.h = 64;

SDL_Rect fillRect;
fillRect.x = animatedSprite.GetX();
fillRect.y = animatedSprite.GetY();
fillRect.w = animatedSprite.getFrameWidth();
fillRect.h = animatedSprite.GetHeight();

SDL_RenderCopy(m_pRenderer, animatedSprite.GetTexture()->GetTexture(), &clip, &fillRect);

希望这有帮助。

很抱歉,我不太明白,我应该如何改进它@LogicStuff尝试用
&fillRect
交换
0
。我用
&fillRect
交换
0
,但是那里什么都没有@逻辑材料
int SDL_RenderCopy(SDL_Renderer*   renderer,
                   SDL_Texture*    texture,
                   const SDL_Rect* srcrect,
                   const SDL_Rect* dstrect)
SDL_Rect clip;
clip.x = 0;
clip.y = 0;
clip.w = 64;
clip.h = 64;

SDL_Rect fillRect;
fillRect.x = animatedSprite.GetX();
fillRect.y = animatedSprite.GetY();
fillRect.w = animatedSprite.getFrameWidth();
fillRect.h = animatedSprite.GetHeight();

SDL_RenderCopy(m_pRenderer, animatedSprite.GetTexture()->GetTexture(), &clip, &fillRect);