Tangent128 / luasdl2

A pure C binding of SDL 2.0 for Lua 5.1, Lua 5.2, and LuaJIT.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

help with animation

lewislepton opened this issue · comments

howdy folks,

i know this isnt a problem solving place. but think it would be good to at least bring these things up.

so what i have been trying with SDL is converting c++ code with SDL to lua-SDL2 code. but there have been many problems, things not working etc. so would like some help on this.
plus if this inforamtion is available for others, then at least other can learn without having to ask. if you get me?

so here is my c++/sdl code. but just need help with getting it to work on lua-SDL2. i have gotten to a certain point. but things like SDL.Rect are still being strange to me. have been able to get the image to load, but its the rendering part.

thanks if you can help

#include <iostream>
#include <SDL2/SDL.h>
#include <SDL2_image/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("image.png");
    SDL_Texture * texture = SDL_CreateTextureFromSurface(renderer, image);
    SDL_SetRenderDrawColor(renderer, 168, 230, 255, 255);
    SDL_RenderClear(renderer);

    while (!quit){
        Uint32 ticks = SDL_GetTicks();
        Uint32 sprite = (ticks / 100) % 3;
        SDL_Rect srcrect = { static_cast<int>(sprite * 32), 0, 32, 32 };
        SDL_Rect dstrect = { 10, 10, 32, 32 };
        SDL_PollEvent(&event);
        switch (event.type){
            case SDL_QUIT:
                quit = true;
                break;
        }
        SDL_RenderClear(renderer);
        SDL_RenderCopy(renderer, texture, &srcrect, &dstrect);
        SDL_RenderPresent(renderer);
    }
    SDL_DestroyTexture(texture);
    SDL_FreeSurface(image);
    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);
    IMG_Quit();
    SDL_Quit();

    return 0;
}

image

Sorry I wasn't in charge of the project in that amount of years. Is this issue still relevant today?