How can i remove a "love.graphics.print" ?

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
Jack5500
Party member
Posts: 149
Joined: Wed Dec 07, 2011 8:38 pm
Location: Hamburg, Germany

How can i remove a "love.graphics.print" ?

Post by Jack5500 »

The Original question:
I created the love.graphics.print in the love.draw() function, but how can I remove it, without clearing the whole screen?
The answer:
1. Define a boolean in the love.load()
2. When your requirements for the clearing are matched change the "boolean" to false (or whatever)
3. After changing it to false call the love.draw()
4. In the love.draw put your love.graphics.print in an if statement that only gets processed when the "boolean" is "true"
5. ???
6. Profit
Last edited by Jack5500 on Wed Dec 07, 2011 9:44 pm, edited 2 times in total.
User avatar
thelinx
The Strongest
Posts: 857
Joined: Fri Sep 26, 2008 3:56 pm
Location: Sweden

Re: Hwo can i remove a "love.graphics.print" ?

Post by thelinx »

Please post some code and describe the actual problem you're having.
User avatar
Jack5500
Party member
Posts: 149
Joined: Wed Dec 07, 2011 8:38 pm
Location: Hamburg, Germany

Re: How can i remove a "love.graphics.print" ?

Post by Jack5500 »

Code: Select all

function love.load()

	width = love.graphics.GetWidth()
	height = love.graphics.GetHeight()
	
	love.graphics.setFont(18)
	
	player ={
	grid_x = 256,
	grid_y = 256,
	act_x = 200,
	act_y = 200,
	speed = 10
	}
	
	playertext ={
	one_x = player.act_x,
	one_y = player.act_y 
	}
	
	WelcomeText ={
	width = width/2,
	height = height/2
	}
end
function love.update(dt)
	playertext.one_y = player.act_y - 24
	playertext.one_x = player.act_x - 16
	player.act_y = player.act_y - ((player.act_y - player.grid_y) * player.speed * dt)
	player.act_x = player.act_x - ((player.act_x - player.grid_x) * player.speed * dt)
	if player
end
function love.draw()
	love.graphics.rectangle("fill",player.act_x,player.act_y,32,32)
	love.graphics.print("Player 1", playertext.one_x, playertext.one_y)
        love.graphics.print("Start the interaction press any key", WelcomeText.width, WelcomeText.height)
end
function love.keypressed(key)
	if key == "up" then
	player.grid_y = player.grid_y - 32
	elseif key == "down" then
	player.grid_y = player.grid_y + 32
	elseif key == "left" then
	player.grid_x = player.grid_x - 32
	elseif key == "right" then
	player.grid_x = player.grid_x + 32
	end
end
"love.graphics.print("Start the interaction press any key", WelcomeText.width, WelcomeText.height)" that's waht I want to remove via an if statement, whcih isn't the actual problem, mor the removing itself :)
User avatar
thelinx
The Strongest
Posts: 857
Joined: Fri Sep 26, 2008 3:56 pm
Location: Sweden

Re: How can i remove a "love.graphics.print" ?

Post by thelinx »

Oh, right.

Well, the screen is cleared before every love.draw anyway, so you just don't call the print() if you don't want to show it on-screen.
User avatar
Jack5500
Party member
Posts: 149
Joined: Wed Dec 07, 2011 8:38 pm
Location: Hamburg, Germany

Re: How can i remove a "love.graphics.print" ?

Post by Jack5500 »

No, I want to remove it after a key is pressed, which I could code in the "function love.keypressed(key)" part. But I would need an actual comamnd to erase that command.

With your suggestion I'd have to make a boolean variable to declare if the text is drawn or not, which isn't the best solution, is it? :huh:
User avatar
thelinx
The Strongest
Posts: 857
Joined: Fri Sep 26, 2008 3:56 pm
Location: Sweden

Re: How can i remove a "love.graphics.print" ?

Post by thelinx »

It is kind of the best solution.

The "real" solution would be to use a Finite State system to manage what part of the game you're in (menu, playing, score screen, et.c.).
There are plenty of libraries for that.
See also the thread in General: FSM - Finite State Machine.
User avatar
Jack5500
Party member
Posts: 149
Joined: Wed Dec 07, 2011 8:38 pm
Location: Hamburg, Germany

Re: How can i remove a "love.graphics.print" ?

Post by Jack5500 »

Okay, thanks very much. I've added the solution to my first posts, so people who are itnerested in the solution can easily see it. Thanks again. I'll surely have more concern, good to know that there is a strong community beyond Löve :D
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 36 guests