Camera and pause problem

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
Lirija
Prole
Posts: 28
Joined: Tue Mar 14, 2017 11:42 am
Contact:

Camera and pause problem

Post by Lirija »

Hi everyone!
So, i'm making this little game just to check if all the tutorials i've seen so far add up and I wanted to implement a pause screen that shows the game screen underneath this way:

Code: Select all

-- inside game.lua
function game.keyreleased(key)
	if key == "escape" then
		love.event.quit()
	elseif key == "p" then
		local screen = love.graphics.newImage ( love.graphics.newScreenshot( ) ) --     <-- HERE
		gamestates.set_state("pause", "game", screen)
	end
end

-- inside pause.lua

function pause:enter(prev_state, ... ) -- seems like noooway's gamestates module prevent me from use self
	pause.screen = ...
end

function pause.draw()
	love.graphics.draw(pause.screen, 0, 0)
	love.graphics.print("Paused", 20, G_height/2)
end

The problem is that it shows the screenshot 4x its size (the camera scale it's already set to 0.25 so actually the screenshot is 16x).
As i was writing the post i came up with a workaround:

Code: Select all

function pause.draw()
	love.graphics.draw(pause.screen, 0, 0, 0, 0.25, 0.25)
	love.graphics.print("Paused", 20, G_height/2)
end
But still can someone explain me what's happening?
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Camera and pause problem

Post by zorg »

A bit hard without knowing what gamestate lib you're using, among a few other tidbits of info that may be necessary for us to give you an answer.
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
Lirija
Prole
Posts: 28
Joined: Tue Mar 14, 2017 11:42 am
Contact:

Re: Camera and pause problem

Post by Lirija »

I'm using the gamestates module from noooway's arkanoid tutorial:

Code: Select all

local gamestates = {}

local current_state = nil 
local loaded = {} -- doesn't require automatically check for this?


function gamestates.state_event(function_name, ...)
	if current_state and type(current_state[function_name]) == "function" then 
		current_state[function_name](...)
	end
end

function gamestates.set_state(state_name, ...)
	gamestates.state_event("exit")
	local old_state_name = get_key_for_value(loaded, current_state) -- get_key_for_value(table, value) return key
	current_state = loaded[ state_name ] -- check if it's already loaded
	if not current_state then -- if not i load it
		current_state = require( "gamestates/" .. state_name )
		loaded[ state_name ] = current_state 
		gamestates.state_event("load", old_state_name, ... ) 
	end
	gamestates.state_event("enter", old_state_name, ... )
end

function get_key_for_value(table, value)
	for k,v in ipairs(table) do
		if v == value then
			return k
		end
	end
end

return gamestates

Anyway i don't believe the problem is related to the gamestates module, probably is the camera:
the game window is 480x672

Code: Select all

function love.conf(t)
	t.title = "Scrolling Shooter Tutorial" -- The title of the window the game is in (string)
	t.version = "0.9.1"         -- The LÖVE version this game was made for (string)
	t.window.width = 480        -- we want our game to be long and thin.
	t.window.height = 672

	-- For Windows debugging
	t.console = true
end
as i wanted to use 24x24 sprites i configured the main as such:

Code: Select all


require "strict" 

gamestates = require "gamestates.gamestates"
camera	   = require "tools.camera"


G_width  = 120 --love.graphics.getWidth() <-- HERE: set globals for screen dimension
G_height = 168 --love.graphics.getHeight()
G_debug	 = true
G_fps 	 = 0 
G_time = 0
G_tileSize = 24
score  	 = 0

function love.load(arg)
	camera.scale.x = 0.25 -- 	<-- upscaled 4x
	camera.scale.y = 0.25
	gamestates.set_state("splash")
end

function love.update(dt)
	G_time = G_time + dt
	gamestates.state_event("update", dt)	
end

function love.draw()
	camera:set()
	gamestates.state_event("draw")
	camera:unset()	
end

function love.keyreleased(key)
	gamestates.state_event("keyreleased", key)
end
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: Camera and pause problem

Post by pgimeno »

How about this?

Code: Select all

function pause.draw()
  love.graphics.push()
  love.graphics.origin()
  love.graphics.draw(pause.screen)
  -- find the correct coordinates here, probably using font:getWidth("Paused") to centre
  love.graphics.print("Paused", some_x, some_y)
  love.graphics.pop()
end
User avatar
Lirija
Prole
Posts: 28
Joined: Tue Mar 14, 2017 11:42 am
Contact:

Re: Camera and pause problem

Post by Lirija »

Yes! This works just fine, i have to check love.graphics.origin in the wiki
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 43 guests