unknown lag?

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
User avatar
baconhawka7x
Party member
Posts: 494
Joined: Mon Nov 21, 2011 7:05 am
Location: Oregon, USA
Contact:

unknown lag?

Post by baconhawka7x »

I just set up my own particle system for my game. But for some reason the frame rate drops after spawning about more than five. It's a very basic particle system.

When the framerate drops, its not too much, but it's defidently noticable.

Here's my setup..

Code: Select all

particle = {}


function particle:spawn(x,y,xvel,yvel,pic)
	table.insert(particle, {timer = 0, x = x, y = y, pic = pic, xvel = xvel, yvel = yvel,height = 16 / 4, width = 16 / 4})
end
function particle:draw()
	for i,v in ipairs(particle) do
		if player.x > v.x - renderdistance and
		player.x > v.x + renderdistance + v.width then
		love.graphics.setColor(255,255,255)
		love.graphics.draw(v.pic,v.x,v.y,0,0.2,0.2)
         end
	end
end
function particle:mech(dt)
	for i,v in ipairs(particle) do
		v.timer = v.timer + dt
		v.x = v.x + v.xvel * dt
		v.y = v.y + v.yvel * dt
		v.xvel = v.xvel * (1 - math.min(dt*player.friction, 1)) --Use the players friction variable, cause I'm lazy.
		v.yvel = v.yvel + player.gravity * dt
		
		if v.timer > 3 then
			table.remove(particle, i)
		end
	end
	for i,v in ipairs(tile) do
		for ia,va in ipairs(particle) do
			if va.x > v.x - renderdistance and
			va.x < v.x + renderdistance + 16 / 4 then
				if va.y + va.height > v.y and
				va.y + va.height < v.y + (v.height / 2) and
				va.x + va.width > v.x + 1 and
				va.x < v.x + v.width - 1 and
				va.kind ~= "fence" and
				va.kind ~= "turrent" then
					va.y = v.y - va.height
					va.yvel = 0
					va.xvel = 0
					va.xvel = va.xvel
					va.yvel = va.yvel
					
			
					
				end
				if va.x + va.width > v.x and
				va.x < v.x + (v.width / 2) and
				va.y + va.height > v.y + 1 and
				va.y < v.y + v.height - 1 and
				va.kind ~= "fence" and
				va.kind ~= "turrent" then
					
					va.xvel = 0
					va.yvel = 0
					va.xvel = va.xvel
					va.yvel = va.yvel
					
					
				end
				if va.x < v.x + v.width and
				va.x > v.x + (v.width / 2) and
				va.y + va.height > v.y + 1 and
				va.y < v.y + v.height - 1 and
				va.kind ~= "fence" and
				va.kind ~= "turrent" then
					
					va.xvel = 0
					va.yvel = 0
					va.yvel = va.yvel
					va.xvel = va.xvel
					
					
					
				end
				if va.y < v.y + v.height and
				va.y > v.y + (v.height / 2) and
				va.x + va.width > v.x + 1 and
				va.x < v.x + v.width - 1 and
				va.kind ~= "fence" and
				va.kind ~= "turrent" then
					va.yvel = 0
					va.xvel = 0
					va.yvel = va.yvel
					va.xvel = va.xvel
					

				end
			end
		end
	end
end
All help is appreciated!:D
User avatar
juno
Citizen
Posts: 85
Joined: Thu May 10, 2012 4:32 pm
Location: London

Re: unknown lag?

Post by juno »

Hmm I can't see anything unusual... I notice you are scaling the particle image to 0.2.. How large are they originally?

Also, a small thing, but you might run into problems with that table.remove code within the for loop
see: viewtopic.php?f=4&t=9869&p=60401&hilit= ... uno#p60401
wat ya mean she's in another castle!?
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: unknown lag?

Post by coffee »

juno wrote:Hmm I can't see anything unusual... I notice you are scaling the particle image to 0.2.. How large are they originally?

Also, a small thing, but you might run into problems with that table.remove code within the for loop
see: viewtopic.php?f=4&t=9869&p=60401&hilit= ... uno#p60401
Juno, why you are pointing to a thread that HE started? He already should it learned! :D
User avatar
juno
Citizen
Posts: 85
Joined: Thu May 10, 2012 4:32 pm
Location: London

Re: unknown lag?

Post by juno »

coffee wrote:Juno, why you are pointing to a thread that HE started? He already should it learned! :D
Haha oh man...Should I be embarrassed? or him?
wat ya mean she's in another castle!?
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: unknown lag?

Post by coffee »

juno wrote:
coffee wrote:Juno, why you are pointing to a thread that HE started? He already should it learned! :D
Haha oh man...Should I be embarrassed? or him?
All of us! Bacon for not remember the lessons that people teach him, you for didn't notice and me for my guilty pleasure of want remember Bacon! :D
Let's not stay off-topic or some people will also remember us of that! :)
rvj
Prole
Posts: 15
Joined: Fri Feb 10, 2012 5:55 pm

Re: unknown lag?

Post by rvj »

Yeah I don't see any glaring problems that would make it slow. I'm suspicious of the collision detection running in mech(dt). If you haven't already, try commenting out the entire nested 'for loop' and seeing if that makes a difference.

I would imagine that 5 or 6 particles all checking your tiles could be time consuming given enough tiles... plus any time there is a slowdown for me it always seems to be a collision detection issue.
Post Reply

Who is online

Users browsing this forum: Amazon [Bot] and 12 guests