Sunil's Blog

I make games! Mostly weird ones.

Code Refactoring

It’s really important. Although many programmers say how important it is, you don’t really realize it until you are in a situation that demands it.

I am working on the introduction state, which requires multiple sprites to be loaded onto the screen at once. Naturally, I embedded all the images into the class, and started to use them. Everything worked well, but a thought occurred to me: I’m definitely going to have to reuse some of these sprites in the future.

I then decided to erase about 50 lines of code, and made each sprite have its own class. I searched online to see if other game developers use the same process, and lo and behold, they do. So each sprite has it’s own class, with its own properties (animations, position, etc.) This will make accessing each sprite and changing each sprite’s values a hell of a lot easier.

1 Comment

  1. It’s sucks to realize you have to throw a ton of code away, but it always pays off in the end. Object oriented code FTW!

Leave a Reply

Your email address will not be published.


© 2019 Sunil's Blog

Theme by Anders NorenUp ↑