Elegant SpriteBatch Usage
Posted: Tue Dec 19, 2017 9:02 am
Hello,
I'm trying to make a 2D platformer that uses one spritesheet and spritebatch for all the foreground objects. However, I don't know how best to structure my code around Spritebatches. I have a Lua table that contains tables of quads like this:
Which get turned into tables of quads in a helper function and then put into my player object for example, but setting the sprite like this seems kinda ugly. Also, if a wrote a function like updateSprite that takes a single Entity (player or enemy) as an argument, I couldn't use a static class variable for the animation quads because I don't know how to access it from an instance, like if there is a Player.quads/Enemy.quads that I set once, and I want to get at that value from within updateSprite(player/enemy).
Am I severely overthinking this? How do you abstract spritebatches elegantly?
Thanks
I'm trying to make a 2D platformer that uses one spritesheet and spritebatch for all the foreground objects. However, I don't know how best to structure my code around Spritebatches. I have a Lua table that contains tables of quads like this:
Code: Select all
local spritedata = {
player = {
{0,0,8,16},
{8,0,8,16}
},
brick = {
{8,48,8,8}
},
...
}
Code: Select all
player:update(dt)
sprites:set(player.sprite_id, player.quads[player.current_frame],player.x, player.y)
-- would like to have something like updateSprite(GameEntity)
Thanks