Cant figure out why im getting 30 FPS

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
grodt
Prole
Posts: 6
Joined: Sun Oct 19, 2014 3:27 am

Cant figure out why im getting 30 FPS

Post by grodt »

All I am doing is drawing simple stuff, text and squares and its getting around 30-33 fps

http://hastebin.com/gizoxoloje.rb

Code: Select all

-- global vars
screen_width =  love.graphics.getWidth()
screen_height = love.graphics.getHeight()
stage = 0

-- Creating tables
Level_One = {}
Player = {}
StartScreen = {}
Bullet = {}

-- Level One
function Level_One.init()
	local self = {}

	function self:draw()
		love.graphics.setColor(44, 62, 80)
		love.graphics.rectangle("fill", 0, 0, screen_width, screen_height)
	end

	return self
end

-- Player
function Player.init()
	local self = {}
	self.width = 25
	self.height = 25
	self.x = (screen_width/2) - (self.width/2)
	self.y = (screen_height) - (self.height * 2)
	self.bullets = {}

	function self:draw()
		love.graphics.setColor(153, 61, 255)
		love.graphics.rectangle("fill", self.x, self.y, self.width, self.height)
	end

	function self:shoot()
		b = Bullet.init(self.x, self.y)
		table.insert (self.bullets, b)
	end

	function self:update(dt)
		if love.keyboard.isDown( "up" ) then
		   self.y = self.y - 200 * dt
		end
		if love.keyboard.isDown( "down" ) then
		   self.y = self.y + 200 * dt
		end
		if love.keyboard.isDown( "right" ) then
		   self.x = self.x + 200 * dt
		end
		if love.keyboard.isDown( "left" ) then
		   self.x = self.x - 200 * dt
		end
		if love.keyboard.isDown( " " ) then
		   self:shoot(dt)
		end
	end

	return self
end

-- Bullet
function Bullet.init(x, y)

	local self = {}
	self.width = 5
	self.height = 5
	self.x = x
	self.y = y

	function self:draw()
		love.graphics.setColor(231, 76, 60)
		love.graphics.rectangle("fill", self.x, self.y, self.width, self.height)
	end

	function self:update(dt)
		self.y = self.y - 200 * dt
	end

	return self
end


function update_bullets(players_bullets, dt)
	for _, b in ipairs(players_bullets) do 
		b:update(dt) 
	end
end

function draw_bullets(players_bullets)
	for _, b in ipairs(players_bullets) do 
		b:draw() 
	end
end

-- Start Screen
function StartScreen.init()
	local self = {}
	self.music = love.audio.newSource("sounds/wake_up_call.mp3")
	self.start_text = "Tap to Start!"
	self.title_text = "NEW WARE ORDER"
	self.credit_text = "© 2014 Super Mega Turbo"
	self.screen_font = love.graphics.newFont("font/PressStart2P.ttf", 20)
	self.title_font = love.graphics.newFont("font/PressStart2P.ttf", 32)
	self.credit_font = love.graphics.newFont("font/PressStart2P.ttf", 12)
	self.start_text_width = self.screen_font:getWidth(self.start_text)
	self.start_text_height = self.screen_font:getHeight(self.start_text)	
	self.title_text_width = self.title_font:getWidth(self.title_text)
	self.credit_text_width = self.credit_font:getWidth(self.credit_text)
	self.title_text_height = self.title_font:getHeight(self.title_text)
	self.blink = true
	self.dt = 0

	function self:draw()
		love.graphics.setFont(self.title_font)
		love.graphics.setColor(155, 89, 182)
		love.graphics.print(self.title_text, (screen_width/2) - (self.title_text_width/2), 200)
		love.graphics.setFont(self.credit_font)
		love.graphics.setColor(255, 255, 255)
		love.graphics.print(self.credit_text, (screen_width/2) - (self.credit_text_width/2), (screen_height - 200))
		love.graphics.setFont(self.screen_font)
		love.graphics.setColor(255, 255, 255)
		if self.blink == true then
			love.graphics.print(self.start_text, (screen_width/2) - (self.start_text_width/2), (screen_height/2) - (self.start_text_height/2))
		end
	end

	function self:update(dt)
		self.music:play()
		self.dt = self.dt + dt
		if self.dt > 0.5 then
			self.blink = not self.blink 
			self.dt = self.dt - 0.5
		end
	end

	return self
end

-- Creating instances
start_screen = StartScreen.init()
level_one = Level_One.init()
player = Player.init()

-- Love game loop
function love.load()
	love.graphics.setBackgroundColor(0,0,0)
end

function love.draw()
	if stage == 0 then 
		start_screen:draw()
	elseif stage == 1 then
		level_one:draw()
		player:draw()
		draw_bullets(player.bullets)
	end 
end

function love.update(dt)
	if love.keyboard.isDown( "return" ) then
   		stage = 1
	end
	if stage == 0 then
		print(love.timer.getFPS( ))
		start_screen:update(dt)
	elseif stage == 1 then
		player:update(dt)
		update_bullets(player.bullets, dt)
		print(love.timer.getFPS( ))
	end
end
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Cant figure out why im getting 30 FPS

Post by Jasoco »

Well for one thing you're printing to the console instead of drawing the FPS to the window somewhere. That can make it slow down on certain systems.

Also, even with that printing to the console, I still get 60FPS. Even after changing it to draw the FPS I still get 60FPS.

Therefore I am going to assume that your display is only 30Hz or something. Try putting a conf.lua file in your project (If you don't have one already.) and disable VSync and see how many FPS you get.
User avatar
undef
Party member
Posts: 438
Joined: Mon Jun 10, 2013 3:09 pm
Location: Berlin
Contact:

Re: Cant figure out why im getting 30 FPS

Post by undef »

Maybe because you call self.music:play() in self.update?
twitter | steam | indieDB

Check out quadrant on Steam!
grodt
Prole
Posts: 6
Joined: Sun Oct 19, 2014 3:27 am

Re: Cant figure out why im getting 30 FPS

Post by grodt »

I found out last night before the thread got approved, but the issue is related to "vsync". Members on IRC told me to add "love.window.setMode(800, 600, {vsync = false})" to the top and this made my fps jump to around 500. I was told I have to fix my drivers. Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 44 guests