Conversion done

This week a primarily been a continuation from what I wrote about last week. Optimizing the game to remove load from the memory however this time, I have removed the pointers from all our background elements which turned out to be a bit more challenging than I expected after doing the Enemies.

The main difference between the EnemyManager and the BackgroundManager was that some elements starts on screen when the game starts. This was easily done by activating the necessary elements when the game started. The next step was to make it so that a new element was added after the current elements edge would come into view. When we were using pointers this was done by checking the first position to see if that elements end would come into view and then make a new one and ad it to the vector. When the first element got of the screen it was deleted and erased meaning that the new element was on the first position and the loop goes on. However when I changed things I first reserve 2 or 3 spaces in a vector and activate and deactivate the different position swapping them around making it hard to specify which element is currently the one that has it and going into view. I made a k´makeshift solution by checking the elements on screen and if one of the elements had a X value larger than a specific value and the end were going into view the manager would activate a new element.

The last problem I encountered was that the main background that is in the back and covers the entire screen had to be reworked. Before the change it was made by having a few rects that were different parts of the texture so that the entire thing would not be on one sprite that were scrolling. The rects were used when the current background would end to create a new background pointer that had a specific part of the texture as a sprite. However I now have to make this before hand when creating all the backgrounds in a vector. When a background is going of the screen the next one in the vector would be added this is repeated until the end.

Doing this is not very hard but it is time consuming changing the functionality that uses pointers to not using pointers so my final advice is that when making objects that are reoccurring  a lot in your game. Pre-allocate as many as you need and re-use them!

Capture

About Philip Olsson

2015 Programming