SDL 2.0 Tutorial-03: Metasprites

So last week we were able to generate a collection of textures and draw them to the screen. In terms of memory this isn’t very efficient. This week we will be creating one texture from a meta  SDL_Surface* . This will be my last part of this basic tutorial, if there are any topics you would like discussed please email me at “info@stephenmeier.net”. If you do occasionally read these posts please let me know which posts you find interesting!



There are many ways to structure game logic, and for a simple 2D game being written in C it comes down to mostly personal preference.

 




3 thoughts on “SDL 2.0 Tutorial-03: Metasprites

  1. I think you forgot to add functions to the functionpointers, like:
    Game.gfx.buildSpr = gfx_buildSpr;
    Game.gfx.destroySpr = gfx_destroySpr;
    Game.screen.drawSpr = screen_drawSpr;

    Without these lines in game_init(void) i can´t run the program successfully. It just crashes on the first use of the functions.

  2. The function pointers are being set on line 60/61 of the second code block but I realized after posting this that styling the code that way may only work with GCC (i.e. the compiler I was using at the time). So that is worth noting.

  3. I´m sorry, Stephen. Didn´t see the lines you mentioned. It works for me for the “buildSpr” and “destroySpr” functions, but i still have to manually assign the function pointer for the “Game.screen.drawSpr” function in game_init().
    I think this was the initial problem. I just played with the code and placed all three functions into init without realising that only the drawSpr function was never assigned in your code ( at least i couldn´t find the assignment on this website).

    But thanks for your code. Very easy to follow and thus easy to learn from.

Leave a Reply

Your email address will not be published.