关于SDL2的贴图上篇已经介绍过了。哪怎么让他动起来呢。我们可以使用SDL_Image也可以使用SDL_LoadBMP来载入图片.
SDL_Surface* pTempSurface = SDL_LoadBMP("image/animate.bmp");
//SDL_Surface* pTempSurface = IMG_Load("image/animate.png");
//SDL_Surface* pTempSurface = IMG_Load("image/animate-alpha.png");
SDL_SetRenderDrawColor(m_pRenderer,255,0,0,255);
m_pTexture = SDL_CreateTextureFromSurface(m_pRenderer,pTempSurface);
SDL_FreeSurface(pTempSurface);
SDL_QueryTexture(m_pTexture,NULL,NULL,&m_sourceRectangle.w,&m_sourceRectangle.h);
m_sourceRectangle.w=128;
m_sourceRectangle.h=82;
void Game::update()
{
m_sourceRectangle.x = 128 * int(((SDL_GetTicks()/100)%6));
}
截图如下:
如何做到图片翻转的呢
1 void Game::render()
2 {
3 SDL_RenderClear(m_pRenderer);
4 //SDL_RenderCopy(m_pRenderer,m_pTexture,&m_sourceRectangle,&m_destinationRectangle);
5 //SDL_RenderCopy(m_pRenderer,m_pTexture,NULL,NULL);
6 SDL_RenderCopyEx(m_pRenderer,m_pTexture,&m_sourceRectangle,&m_destinationRectangle,0,NULL,SDL_FLIP_HORIZONTAL);//此句起的作用
7 SDL_RenderPresent(m_pRenderer);
8 }