Page 1 of 1

Are meshes visible in LoVE? If so, what is wrong with this?

Posted: Tue Mar 18, 2014 12:47 pm
by StaleNacho
After reading a bit about Lua, I decided to start tinkering with a program for LoVE. This proved difficult. The idea is that I simply draw a rectangle with the mouse, similar to how the desktop creates a bounding box when you click and then drag.

With this code I am expecting a purple block to appear after I release the mouse button but nothing happens.

Does all drawing to the screen NEED to take place is love.draw?

Code: Select all

function love.load()
	love.mouse.setPosition(1,1)
	cpx = 1
	cpy = 1
	rpx = 1
	rpy = 1
end

function love.update(dt)
	x = love.mouse.getX()
	y = love.mouse.getY()

	function love.mousepressed(x,y,button)
		if button == "l"
		then cpx = x
			 cpy = y
		end
	end
	function love.mousereleased(x,y,button)
		if button == "l"
		then rpx = x
			 rpy = y
		end
	end
	vertices = 
{
		{cpx,cpy,
		0,0,
		255,0,255
	},
		{rpx,rpy,
		0,0,
		255,0,255
	},
		{cpx,rpy,
		0,0,
		255,0,255
	},
		{rpx,cpy,
		0,0,
		255,0,255
	}
}

	function love.mousereleased(x,y,button)
		if button == "l"
		then plop = love.graphics.newMesh(vertices, tx, "fan")
		love.graphics.draw(plop, cpx, cpy)
		end
	end
end

function love.draw()
end
Thanks for the consideration :)

Re: Are meshes visible in LoVE? If so, what is wrong with th

Posted: Tue Mar 18, 2014 1:56 pm
by ArchAngel075
Not exactly an answer to the OP but from my experience and knowledge you shouldn't define love.mousepressed etc inside love.update

secondly any love.draw calls must be done in love.draw()!

so instead put the love.mousereleased etc functions outside the love.update and to draw the mesh you would need to call love.graphics.draw(plop, cpx, cpy)

inside love.draw() (first make sure plop exists, ie

Code: Select all

if plop then 
 --draw
end
I would manually reposition and work out what you provided but its abit confusing to read and reposition it all cause of the unfamiliar method you define your love.mouse### functions....

Re: Are meshes visible in LoVE? If so, what is wrong with th

Posted: Tue Mar 18, 2014 2:05 pm
by alesan99
^ that and

If you really want to draw something outside of love.draw you'll need to use love.graphics.present(), but you should still draw in love.draw().

Re: Are meshes visible in LoVE? If so, what is wrong with th

Posted: Thu Mar 20, 2014 11:23 am
by StaleNacho
Thanks for the input guys, I made the appropriate fixes and nothing shows up when I expect it to still.

Oh, well-- It's all a learning process. :)

Re: Are meshes visible in LoVE? If so, what is wrong with th

Posted: Thu Mar 20, 2014 4:21 pm
by Ref
And you really should have defined a texture to be used (tx not defined).
Takes a while to become familiar with what all the settings for meshes should be.
Attached, please find a simple demo.
Probably not what you what but something to play with to see what all the parameters do.
Best

Re: Are meshes visible in LoVE? If so, what is wrong with th

Posted: Fri Mar 21, 2014 6:50 pm
by alesan99
StaleNacho wrote:Thanks for the input guys, I made the appropriate fixes and nothing shows up when I expect it to still.
I attached a working version.
Used love.polygon instead of meshes.
I made the code easy to understand so please look at it.

Re: Are meshes visible in LoVE? If so, what is wrong with th

Posted: Fri Mar 21, 2014 7:52 pm
by StaleNacho
alesan99 wrote:
StaleNacho wrote:Thanks for the input guys, I made the appropriate fixes and nothing shows up when I expect it to still.
I attached a working version.
Used love.polygon instead of meshes.
I made the code easy to understand so please look at it.
Thank you so much :)

thats pretty great of you, I really appreciate it!

Gonna get to studying right now :nyu: