从SMFL到SDL 2.0

时间:2017-04-06 07:50:58

标签: c++

以下是SMFL中的一些代码

    RenderWindow window(VideoMode(320, 480), "The Game!");
    Texture t1,t2,t3;
    t1.loadFromFile("images/tiles.png");
    t2.loadFromFile("images/background.png");
    t3.loadFromFile("images/frame.png");

    Sprite s(t1), background(t2), frame(t3);

SDL 2.0是否具有这样的功能以及如何将它们转换为SDL 2.0

1 个答案:

答案 0 :(得分:1)

是的,一切都在那里: https://programmersranch.blogspot.kr/2014/03/sdl2-animations-with-sprite-sheets.html

#include <SDL.h>
#include <SDL_image.h>

int main(int argc, char ** argv)
{
bool quit = false;
SDL_Event event;

SDL_Init(SDL_INIT_VIDEO);
IMG_Init(IMG_INIT_PNG);

SDL_Window * window = SDL_CreateWindow("SDL2 Sprite Sheets",
    SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640,
    480, 0);
SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, 0);
SDL_Surface * image = IMG_Load("spritesheet.png");
SDL_Texture * texture = SDL_CreateTextureFromSurface(renderer,
    image);

while (!quit)
{
    SDL_WaitEvent(&event);

    switch (event.type)
    {
    case SDL_QUIT:
        quit = true;
        break;
    }

    SDL_RenderCopy(renderer, texture, NULL, NULL);
    SDL_RenderPresent(renderer);
}

SDL_DestroyTexture(texture);
SDL_FreeSurface(image);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
IMG_Quit();
SDL_Quit();

return 0;
}