help creating a background with for i statement [closed]

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
bobbymcbobface
Citizen
Posts: 78
Joined: Tue Jun 04, 2019 8:31 pm

help creating a background with for i statement [closed]

Post by bobbymcbobface »

So here's the problem - i need help creating a certain amount of squares to fit my screen width + screen height

some helpful info -
1 in gridXCount/gridYCount is equal to 8 squares of the background
so if gridYCount and gridXCount is equal to 10 then there would 6400 squares in total across the screen

i kind of have a solution using tables but it seems to just make the game stop working (freeze)
Game.love
(14.77 KiB) Downloaded 124 times
Last edited by bobbymcbobface on Wed Dec 04, 2019 7:50 am, edited 1 time in total.
I make games that run on potatoes :P
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: help creating a background with for i statement

Post by zorg »

I figure the issue is lines 116-133 in Game.lua, but i'm not completely sure what part you have problems with.
Do you just want to calculate how many squares fit inside an area the size of the window's dimensions? If so, then the solution is simple:

Code: Select all

local width, height = love.graphics.getDimensions()
local gridSquareSize = 8
local squareColumns, squareRows = math.floor(width / gridSquareSize), math.floor(height / gridSquareSize)
The above assumes that i didn't misunderstand your terminology about grids being 8 squares of the background. i assumed you meant pixels by squares; if that's wrong, then just multiply the gridSquareSize by however many pixels you have in a background square.

Not sure why it'd freeze though, haven't looked too deeply at the code.
It's kinda worrying though that apparently schools don't teach kids how division works; 6400/8 is exactly 64/8 * 100, (or 2^6 / 2^3 * 100) which is (2^3 * 100 or) 8 * 100 or 800...
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
bobbymcbobface
Citizen
Posts: 78
Joined: Tue Jun 04, 2019 8:31 pm

Re: help creating a background with for i statement

Post by bobbymcbobface »

Thanks I'll check this out when I get the chance and get back to you if needed :)
I make games that run on potatoes :P
User avatar
bobbymcbobface
Citizen
Posts: 78
Joined: Tue Jun 04, 2019 8:31 pm

Re: help creating a background with for i statement

Post by bobbymcbobface »

ok so i managed to implement your idea exactly like i wanted but there's one problem - it's laggy as hell i'm guessing it's because i'm drawing a ton of squares is there a work around for this? - i'm aiming for a background similar to Snayke the love2d version of snake here's the snippet of code i'm using

Code: Select all

for a = 1, squareRows do
	for b = 1, squareColumns do
 		--print(A)
		table.insert(Background.Segments, 1, {x = a, y =  b})
		drawCell(a, b)
		A = A + 1
		print(i)
	end
end
I make games that run on potatoes :P
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: help creating a background with for i statement

Post by zorg »

Is that your creation code, your draw code, or both? Because i'd set up the segments first, then only draw the cells in love.draw as to not create tons of segments each frame... the print statement might also slow things down.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
bobbymcbobface
Citizen
Posts: 78
Joined: Tue Jun 04, 2019 8:31 pm

Re: help creating a background with for i statement

Post by bobbymcbobface »

--atachment removed--
Ok I managed to fix the drawing of the background but for some reason the background isn't resizing when changing the screen size (in settings) to full screen - can you help please?

thanks
I make games that run on potatoes :P
Post Reply

Who is online

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