Mining Game Optimization

Mottafier

Member
Hello!

I have been working with my brother on a mining game recently, featuring many small ore objects that span over the length of the screen, and pretty far down. There are probably over a thousand in the room total. Obviously this is going to cause issues, and I've been trying to optimize it for a few days now with little success. The closest I've come is deactivating all of the ore parent's objects, then activating all the objects within the view.game.PNG
In this screenshot, I've created a second view and zoomed out, just to give you a better idea. The objects within the game view activate as they come into camera range, and the objects out of camera range deactivate. On the left are two numbers; FPS and below it FPS real. The game runs smooth when at 60 FPS, and the game runs smoothly while there is no ore on screen, but as soon as you dig down, FPS drops. I have also tried activating and deactivating on an alarm instead of every step, but when the alarm is a higher number, such as a 6 step alarm, when that goes off there is a larger framerate spike.

I should also note that the ore objects themselves aren't so bad; I've experimenting with seeing how many there can be active in total without lag. If I'm not actively deactivating or activating instances, the room can hold about twice the amount of active ore objects as in the image, with relatively smooth framerate. So I don't think the objects themselves are the issue, although I'm sure there is room for improvement.

Any solutions??
 

GMWolf

aka fel666
You are just digging yourself into a hole with objects.
You can try to optimize them as much as you like, you are still starting off with a fundamentally slow concept.

Look into tilemaps. Tilemaps should let you represent your world at very little cost.
They can both render fast, and allow you to do fast collision detection.
 
Last edited:

TheouAegis

Member
You are just doing yourself into a hole with objects.
Badump tss šŸ„

Use tiles for ores. then you can either reference to tiles directly or use a grid / 2D array the hold the locations of each or and ore type, if you are going to have different types. Take the coordinates of the drill and divided by the size of your tile, floored off, and that will be the first index in the grid / array, then you loop through the second index to see if there is an ore there and how far down it is. Or if you use tiles correctly, just loop through the y coordinates, since you already have the x coordinate of the drill.
 

Mottafier

Member
Badump tss šŸ„

Use tiles for ores. then you can either reference to tiles directly or use a grid / 2D array the hold the locations of each or and ore type, if you are going to have different types. Take the coordinates of the drill and divided by the size of your tile, floored off, and that will be the first index in the grid / array, then you loop through the second index to see if there is an ore there and how far down it is. Or if you use tiles correctly, just loop through the y coordinates, since you already have the x coordinate of the drill.
thank you!! I did this, and it works well! Only issue: when you mine ore, itā€™s alpha level is supposed to lower based on how much health the ore has left. This was simple with objects, but I donā€™t see an easy way to manipulate individual tileā€™s alpha in the map...
new ideas??
 

GMWolf

aka fel666
thank you!! I did this, and it works well! Only issue: when you mine ore, itā€™s alpha level is supposed to lower based on how much health the ore has left. This was simple with objects, but I donā€™t see an easy way to manipulate individual tileā€™s alpha in the map...
new ideas??
You could render partially destroyed ores separately. Or remove them from tilemap and use draw_sprite or an instance or something to render it.
 

Yal

šŸ§ *penguin noises*
GMC Elder
You could do a middle ground approach where you use objects for ore, but tiles for normal ground (you only seem to have a few dozen ore deposits active at once, while there's probably over a thousand dirt tiles on-screen).

Another idea is to have "ongoing destruction" objects for currently-mined tiles, which are cracks that get larger as the ore's health is depleted. You can't really give tiles gradually-changing variables, so the idea is that when you're mining something, you either add to the "ongoing destruction" on that map cell (if there was one there) or you spawn a new one, and then that object uses the tile type to figure out how much effort is needed to mine the tile it's responsible for. If the player leaves it, it slowly recedes and eventually destroys itself, undoing the damage to the tile.
 

TheouAegis

Member
Or you expand your tileset to have ores at various stages of supply and just change the tile as the supply of ore goes down. You'd need an array to hold the amount of ore at each position.
 
Top