Grid placing...

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
FadeRemix
Prole
Posts: 1
Joined: Fri Apr 16, 2021 1:37 pm

Grid placing...

Post by FadeRemix »

Hello! I am new to love2d but I have been messing with it for about 2 weeks or so, so I kind of know the basics. but is there any way to make a grid type thing where you can place images and make them line up like sprites? thanks!
User avatar
tomxp411
Prole
Posts: 29
Joined: Thu Apr 08, 2021 5:41 pm

Re: Grid placing...

Post by tomxp411 »

You'd probably have to draw one yourself.

I draw grids from time to time, and it's usually a simple operation. You need two FOR loops, and you increment either based on a fraction of the screen size or a number of pixels, depending on your intent.

So if your window is 1920x1080, and you want a 32x32 grid...

Code: Select all

gridSize=32 
for x=0, 1920, gridSize do
    love.graphics.line(x, 9, x, 1080)
end
for y=0, 1080, gridSize do
    love.graphics.line(0, y, 1920, y)
end
To actually place objects on the grid, you'll need to multiply by the grid column. So if you want a sprite in column 3, row 5:

Code: Select all

sprite.x = 3 * 32
sprite.y = 5 * 32
or, in a more proper style:

Code: Select all

sprite.x = sprite.gridX * gridSize
sprite.y = sprite.gridY * gridSize
of course, you'll probably want to make Grid an object, so

Code: Select all

sprite.x = sprite.gridX * Grid.width
sprite.y = sprite.gridY * Grid.height
Post Reply

Who is online

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