gpt4 book ai didi

c++ - 从 SMFL 到 SDL 2.0

转载 作者:行者123 更新时间:2023-11-30 05:15:02 24 4
gpt4 key购买 nike

这是 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

最佳答案

是的,一切都在那里: 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;
}

关于c++ - 从 SMFL 到 SDL 2.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43248971/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com