Using sprites to create a map

Show off your games, demos and other (playable) creations.
Post Reply
szabo_tudor
Prole
Posts: 1
Joined: Mon Jul 01, 2019 10:16 am

Using sprites to create a map

Post by szabo_tudor » Mon Jul 01, 2019 10:39 am

(Sorry for bad spelling)
Hello, I am trying to create a map for a game I am working on, but I can't seem to find a way to do it without it lagging the whole game.
So I have some sprites(32x32 pixels), witch i use to build the map like a puzzle, and then move the map behind the player to make it look like he is moving.
I was thinking I could use something like (image):replacePixels, but I'm not shure it will work. Any one have sugestions?

User avatar
pgimeno
Party member
Posts: 1690
Joined: Sun Oct 18, 2015 2:58 pm

Re: Using sprites to create a map

Post by pgimeno » Mon Jul 01, 2019 6:48 pm

Hi, welcome to the forums! It's hard to give any advice without looking at what you're doing. Using Image:replacePixels to draw a background sounds like a bad idea performance wise. One way is to draw the map at a different coordinate every frame (hopefully that's what you mean by "move the map"); if it's causing you performance issues, then we need to know more about what you're doing exactly, because it's not supposed to do so. Could you show us the code? Also, what size is your image?

CrimsonGuy
Prole
Posts: 27
Joined: Thu Apr 04, 2019 3:32 pm

Re: Using sprites to create a map

Post by CrimsonGuy » Mon Jul 01, 2019 10:58 pm

Im just guessing, but you probably have a lot of sprites and drawing them one by one with a call to love.graphics.draw which is bad for performance since each love.graphics.draw generates a call to the gpu. You could use a Spritebatch https://love2d.org/wiki/SpriteBatch to draw all the sprites on the map in a single call and improve performance by a lot. I was having a similar problem with my prototype and fixed it with Spritebatch.

User avatar
pgimeno
Party member
Posts: 1690
Joined: Sun Oct 18, 2015 2:58 pm

Re: Using sprites to create a map

Post by pgimeno » Mon Jul 01, 2019 11:49 pm

Oh, I think you're right CrimsonGuy, I didn't read the OP carefully enough it seems.

@szabo_tudor If you're using 11.x, then just using a texture atlas for all the map tiles would suffice to trigger autobatching, which should already improve performance significantly.

By the way, this subforum is for showing your games and creations. The questions normally go in Support and Development.

Post Reply

Who is online

Users browsing this forum: Exabot [Bot] and 2 guests