Help optmising city simulation game!

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
rougan
Citizen
Posts: 58
Joined: Wed Aug 12, 2015 10:30 am

Help optmising city simulation game!

Post by rougan »

Hiya, so i've been working on a city simulation game and currently have a map consisting of 200 tiles, which are currently drawn in a for loop by graphics.draw(). However,I understand that this is not terribly effecient and the only alternative I have come across are spritebatches, but these don't seem to be suitable as the player has the ability to build bulidngs,lakes and roads etc, therefore changing the image of the tile that is being drawn; and sprite batches can only consist of one image?

Other than putting as little code as possible in the for loop, I don't really have any other ideas for optimisation! Any suggestions would be appreciated, thanks!! :)
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Help optmising city simulation game!

Post by Nixola »

You can use a spritesheet as the spritebatch texture, and add quads to it so that you only add one part of the image.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
rougan
Citizen
Posts: 58
Joined: Wed Aug 12, 2015 10:30 am

Re: Help optmising city simulation game!

Post by rougan »

Nixola wrote:You can use a spritesheet as the spritebatch texture, and add quads to it so that you only add one part of the image.
Thanks, i'll look into it!
Rickton
Party member
Posts: 128
Joined: Tue Mar 19, 2013 4:59 pm
Contact:

Re: Help optmising city simulation game!

Post by Rickton »

You could probably use a canvas.
Possession - Escape from the Nether Regions, my roguelike made in LÖVE for the 2013 7-Day Roguelike Challenge
And its sequel, simply called Possession , which is available on itch.io or Steam, and whose engine I've open-sourced!
User avatar
Imaculata
Party member
Posts: 102
Joined: Mon Aug 10, 2015 2:51 pm

Re: Help optmising city simulation game!

Post by Imaculata »

A game like Sim City would probably have all the sprites in one spritesheet, including the buildings and all their animations.
Or you could have a separate table for all the building locations, and draw only those that are visible on top of the map.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Help optmising city simulation game!

Post by kikito »

My advise on optimization would be: try your code without optimizations first. If it works ok in your target machine (i.e. a low-spec pc), then move on to the next thing - don't "optimize" what is fast enough. Don't leave optimizations in "just in case". The time you save can be employed in making your game better. Or at least in optimizing what really needs to be optimized.
When I write def I mean function.
Sosolol261
Party member
Posts: 125
Joined: Wed Nov 26, 2014 6:43 am

Re: Help optmising city simulation game!

Post by Sosolol261 »

rougan wrote:Hiya, so i've been working on a city simulation game and currently have a map consisting of 200 tiles, which are currently drawn in a for loop by graphics.draw(). However,I understand that this is not terribly effecient and the only alternative I have come across are spritebatches, but these don't seem to be suitable as the player has the ability to build bulidngs,lakes and roads etc, therefore changing the image of the tile that is being drawn; and sprite batches can only consist of one image?

Other than putting as little code as possible in the for loop, I don't really have any other ideas for optimisation! Any suggestions would be appreciated, thanks!! :)
Store tiles in a table BEFORE drawing. Then draw using the data of the table. Should be a bit more efficient.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 49 guests