[Solved]Stop mousepress being brought into another gamestate

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
Sabun
Prole
Posts: 5
Joined: Tue Feb 19, 2013 3:18 am
Location: Ampang, Malaysia

[Solved]Stop mousepress being brought into another gamestate

Post by Sabun »

Hi there,
I have two issues currently with my LÖVE code right now. First, my mousepress is being brought over to another gamestate unintentionally. I have a "main" gamestate, and an "optionmenu" gamestate in this code. The buttons in "main" are positioned the same in "optionmenu". So, when I click the button "Options", it changes to "optionmenu" but at the same time it clicks the button "Windowed" which toggles fullscreen in gamestate "optionmenu".

Code: Select all

function love.mousepressed(x, y, button)
	if gamestate == "menu" then
		if button == 'l' then
			--user pressed left click
			button_click(x,y)
		end
	end

	--options menu mouse clicks
	if gamestate == "optionmenu" then
		if button == 'l' then
			--user pressed left click
			optionbutton_click(x,y)
		end
	end
end
This doesn't happen for the other buttons. This only happens to the button that changes gamestate and is overlapping the other button in the coming gamestate. It's probably an obvious fix, but I just can't see it.

The second issue I have is with highlighting my buttons, which are images, using love.graphics.setColorMode( "combine" ) and love.graphics.setColor(255,255,255) as below:

Code: Select all

function button_draw()
	--this gets called in love.draw()
	for i, v in ipairs(button) do
		--accessing content from button table
		--mode = love.graphics.getColorMode()
		if v.mouseover == true then
			--highlight selected button
			love.graphics.setColorMode( "combine" )
			love.graphics.setColor(255,255,255)
			love.graphics.draw(v.pic, v.x - (v.pic:getWidth()/2), v.y)
		end

		if v.mouseover == false then
			--remove highlight from selected button
			love.graphics.setColorMode( "replace" )
			love.graphics.draw(v.pic, v.x - (v.pic:getWidth()/2), v.y)	
		end
		
	end
end
It highlights the upper buttons great! But the Exit button is problematic. The Exit button is highlighted along with the background image, which is not intended.

Any help or assistance in this regard is greatly appreciated :)
P.S: To exit my problem.love at any time, just hit Escape on your keyboard.
Don't worry about the background image, it's there just to show the Exit button highlighting issue.
Attachments
problem.love
(247.9 KiB) Downloaded 62 times
Last edited by Sabun on Tue Feb 19, 2013 8:05 am, edited 1 time in total.
User avatar
substitute541
Party member
Posts: 484
Joined: Fri Aug 24, 2012 9:04 am
Location: Southern Leyte, Visayas, Philippines
Contact:

Re: Stop mousepressed being brought into another gamestate

Post by substitute541 »

The first problem IS kinda obvious. All you have to do is to turn the double-if statements into an if-elseif block (I refer to a group of statements as blocks).

For the second problem, just reset the default colorMode at the end of the function. Actually, it is a good practice to reset all the colors and colorMode by using setColor(255, 255, 255) and setColorMode("replace")*.

EDIT : *at the end of EVERY draw function that is called by love.draw.
Currently designing themes for WordPress.

Sometimes lurks around the forum.
Sabun
Prole
Posts: 5
Joined: Tue Feb 19, 2013 3:18 am
Location: Ampang, Malaysia

Re: Stop mousepressed being brought into another gamestate

Post by Sabun »

Thank you substitute541!

I didn't realize I was misplacing the love.graphics.setColorMode("replace"). I was trying to reset it, but in the wrong if block. How can I give you karma as thanks?

Fast, easy, and problem solving reply. Thanks a bunch mate :ultrahappy:
User avatar
substitute541
Party member
Posts: 484
Joined: Fri Aug 24, 2012 9:04 am
Location: Southern Leyte, Visayas, Philippines
Contact:

Re: Stop mousepressed being brought into another gamestate

Post by substitute541 »

Sabun wrote:Thank you substitute541!

I didn't realize I was misplacing the love.graphics.setColorMode("replace"). I was trying to reset it, but in the wrong if block. How can I give you karma as thanks?

Fast, easy, and problem solving reply. Thanks a bunch mate :ultrahappy:
No problem! As for the karma, it was broken in the last update of the Love2D forums (I keep saying Love2D instead of Love with an accent, because It's just takes too long).
Currently designing themes for WordPress.

Sometimes lurks around the forum.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest