Is this the most effect simple way to display a moving image? SDL2
- by user36324
I've looked around for tutorials on SDL2, but there isnt many so I am curious i was messing around and is this an effective way to move an image. One problem is that it drags along the image to where it moves.
#include "SDL.h"
#include "SDL_image.h"
int main(int argc, char* argv[])
{
    bool exit = false;
    SDL_Init(SDL_INIT_EVERYTHING);
    SDL_Window *win = SDL_CreateWindow("Hello World!", 100, 100, 640, 480, SDL_WINDOW_SHOWN);
    SDL_Renderer *ren = SDL_CreateRenderer(win, -1,
    SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
    SDL_Surface *png = IMG_Load("character.png");
    SDL_Rect src;
    src.x = 0;
    src.y = 0;
    src.w = 161;
    src.h = 159;
    SDL_Rect dest;
    dest.x = 50;
    dest.y = 50;
    dest.w = 161;
    dest.h = 159;
    SDL_Texture *tex = SDL_CreateTextureFromSurface(ren, png);
    SDL_FreeSurface(png);
    while(exit==false){
        dest.x++;
        SDL_RenderClear(ren);
        SDL_RenderCopy(ren, tex, &src, &dest);
        SDL_RenderPresent(ren);
    }
    SDL_Delay(5000);
    SDL_DestroyTexture(tex);
    SDL_DestroyRenderer(ren);
    SDL_DestroyWindow(win);
    SDL_Quit();
}