Question about changing sprites
Posted: Thu Sep 28, 2017 8:03 am
Sorry, this question really isn't LOVE specific, but it pertains to game development potentially in LOVE. So, keeping track of graphical state is annoying. It can lead to unintended behavior whose origins are obnoxious to track down, and it couples game logic with graphics. I had the (probably not original) idea to resolve these problems by having a sort of "stateless" test in the update function of each drawn entity, like so:
And so on, and you could have nested scenarios as well.
My question is, is there anything significantly wrong with doing it this way? I feel like it's fairly obvious, but I've never seen anyone use it. It's obviously not as efficient as just setting it one time, coupled with the player's behavior, but does testing a few conditions every frame really affect performance that much, in practice? I'm pretty clueless when it comes to performance, so I'd appreciate any feedback.
Code: Select all
if self.isStanding then
self.sprite = sprite.standing
elseif self.isWalking then
self.sprite = sprite.walking
self.sprite:update(dt) --probably an easy way to have this not trigger on the first frame you play, but that's not important for this example
elseif self.isDucking then
self.sprite = sprite.ducking
end
My question is, is there anything significantly wrong with doing it this way? I feel like it's fairly obvious, but I've never seen anyone use it. It's obviously not as efficient as just setting it one time, coupled with the player's behavior, but does testing a few conditions every frame really affect performance that much, in practice? I'm pretty clueless when it comes to performance, so I'd appreciate any feedback.