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

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
StaleNacho
Prole
Posts: 13
Joined: Sat Aug 24, 2013 2:02 pm

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

Post 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 :)
User avatar
ArchAngel075
Party member
Posts: 319
Joined: Mon Jun 24, 2013 5:16 am

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

Post 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....
User avatar
alesan99
Citizen
Posts: 53
Joined: Sun Feb 09, 2014 3:13 am
Contact:

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

Post 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().
User avatar
StaleNacho
Prole
Posts: 13
Joined: Sat Aug 24, 2013 2:02 pm

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

Post 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. :)
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

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

Post 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
Attachments
StaleNatcho.love
Simple example of using meshes
(46.3 KiB) Downloaded 100 times
User avatar
alesan99
Citizen
Posts: 53
Joined: Sun Feb 09, 2014 3:13 am
Contact:

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

Post 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.
Attachments
drag.love
(418 Bytes) Downloaded 109 times
User avatar
StaleNacho
Prole
Posts: 13
Joined: Sat Aug 24, 2013 2:02 pm

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

Post 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:
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests