when does your game slow down?

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.
User avatar
napco
Party member
Posts: 129
Joined: Fri Jun 12, 2009 9:28 pm
Location: Ital... ehm...

Re: when does your game slow down?

Post 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.
User avatar
hertzcastle
Party member
Posts: 100
Joined: Sun Jan 04, 2009 4:51 pm
Location: brighton, uk

Re: when does your game slow down?

Post by hertzcastle »

thnaks napco, but i really don't understand the maths there :(
how much faster is your version than just setscissor()?
x
User avatar
napco
Party member
Posts: 129
Joined: Fri Jun 12, 2009 9:28 pm
Location: Ital... ehm...

Re: when does your game slow down?

Post 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())
User avatar
Fizzadar
Prole
Posts: 30
Joined: Mon Oct 26, 2009 6:18 pm

Re: when does your game slow down?

Post by Fizzadar »

When I loaded a new image on draw I managed to fill my 4GB's of RAM before it exploded :D
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: when does your game slow down?

Post by bartbes »

So your video card shares memory? Dare I say "lame"? Yes.
User avatar
Fizzadar
Prole
Posts: 30
Joined: Mon Oct 26, 2009 6:18 pm

Re: when does your game slow down?

Post 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?
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: when does your game slow down?

Post 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!
User avatar
hertzcastle
Party member
Posts: 100
Joined: Sun Jan 04, 2009 4:51 pm
Location: brighton, uk

Re: when does your game slow down?

Post by hertzcastle »

napco, what does cameraX/Y relate to? could you explain your code a little? i dont quite understand...x
User avatar
napco
Party member
Posts: 129
Joined: Fri Jun 12, 2009 9:28 pm
Location: Ital... ehm...

Re: when does your game slow down?

Post 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.
User avatar
hertzcastle
Party member
Posts: 100
Joined: Sun Jan 04, 2009 4:51 pm
Location: brighton, uk

Re: when does your game slow down?

Post by hertzcastle »

ahhhhh, got it working! thanks a bunch napco!
x
Post Reply

Who is online

Users browsing this forum: No registered users and 56 guests