Page 2 of 2

Re: when does your game slow down?

Posted: Sat Nov 14, 2009 6:54 pm
by napco
Well, it's not true... Scissor prevents the images to be displayed, not the love.graphics.draw call, so the game slows down also (already tried). A good algorithm would be:

Code: Select all

function draw()
	x1 = 1 - math.ceil(camera_x / 32)
	x2 = 15 - math.floor(camera_x / 32)
	y1 = 1 - math.ceil(camera_y / 32)
	y2 = 10 - math.floor(camera_y / 32)
	if x1 < 1 then
		x1 = 1
	end
	if x2 > self.wide then
		x2 = map_wide
	end
	if y1 < 1 then
		y1 = 1
	end
	if y2 > self.high then
		y2 = map_high
	end
	-- Draw lower/medium tiles
	for x = x1, x2 do
		for y = y1, y2 do
			-- Set tile coordinates
			local ox = x * 32 - 16 + math.floor(camera_x)
			local oy = y * 32 - 16 + math.floor(camera_y)
			-- Draw tile
			etc...
		end
	end
end
Where 32 is the tile width/height, 15 and 10 are screen width / tile width and screen height / tile height.

Re: when does your game slow down?

Posted: Sun Nov 15, 2009 10:04 am
by hertzcastle
thnaks napco, but i really don't understand the maths there :(
how much faster is your version than just setscissor()?
x

Re: when does your game slow down?

Posted: Mon Nov 16, 2009 1:09 am
by napco
This algorithm's speed is not influenced by the width and height values of the map (in tiles)... You can try to compare my algorithm on a 1000x1000 map with a normal algorithm using setScissor(x, y, w, h), checking FPS with love.graphics.setCaption(love.timer.getFPS())

Re: when does your game slow down?

Posted: Mon Nov 16, 2009 6:30 pm
by Fizzadar
When I loaded a new image on draw I managed to fill my 4GB's of RAM before it exploded :D

Re: when does your game slow down?

Posted: Mon Nov 16, 2009 6:48 pm
by bartbes
So your video card shares memory? Dare I say "lame"? Yes.

Re: when does your game slow down?

Posted: Mon Nov 16, 2009 6:54 pm
by Fizzadar
bartbes wrote:So your video card shares memory? Dare I say "lame"? Yes.
No it doesn't, but you make a good point, WTF.

It's a 9600GT, with 512MB of it's own memory, but I was using love.graphics, might have been under love.update, would that change where it's loaded too?

Re: when does your game slow down?

Posted: Mon Nov 16, 2009 7:30 pm
by bartbes
Maybe it's just that the decoded image stays in memory, even though creating new images every tame seems to imply you don't store references, which in turn should make the garbage collector eat (tm) the memory. Anyway, even if you need a lot of images spawned a lot, just use resource caching!

Re: when does your game slow down?

Posted: Thu Nov 19, 2009 10:13 am
by hertzcastle
napco, what does cameraX/Y relate to? could you explain your code a little? i dont quite understand...x

Re: when does your game slow down?

Posted: Thu Nov 19, 2009 11:52 am
by napco
Camera x and y are the offset of the map. You can change them with love.keyboard.isDown(directional keys) to simulate map scrolling.

Re: when does your game slow down?

Posted: Fri Nov 20, 2009 1:06 pm
by hertzcastle
ahhhhh, got it working! thanks a bunch napco!
x