Hi,
I'm new here; I had a question about how to draw things.
I would like to draw an image when i click with my mouse.
And I want the image to be drawn when I click somewhere else without deleting the old one.
How can I do this?
function love.load()
img = {
stone = love.graphics.newImage("stone.png"),
}
function love.draw(dt)
love.graphics.draw(img.stone,a-9,b-9)
end
function love.mousepressed(x, y, button)
x, y = love.mouse.getPosition( )
pressed = 1
print(pressed)
a=x
b=y
end
I tried this but, of course, the image disappears when I click somewhere else.
function love.load()
img = {
stone = love.graphics.newImage("stone.png")
}
objects = {}
end
function love.draw()
--A for loop that draws all the objects in our objects table.
--The _ is the index of the current object in the loop. obj is the value of the current object in the loop.
--In this case it's the table we're inserting in the mousepressed callback.
for _,obj in ipairs(objects) do
love.graphics.draw(obj.image, obj.x, obj.y)
end
end
function love.mousepressed(x,y, button)
if button == 'l' then
--Insert a table into our objects table.
--The new table contains a reference to the image, and the coordinates where to draw it.
table.insert(objects, {image = img.stone, x=x, y=y})
end
end
Last edited by nevon on Fri Feb 04, 2011 8:08 pm, edited 1 time in total.
for i=0,40 do
for j=0,30 do
if t[i][j].z == 1 then
love.graphics.draw(img.ston1, t[i][j].x, t[i][j].y)
elseif t[i][j].z == 2 then
love.graphics.draw(img.stone2, t[i][j].x, t[i][j].y)
end
end
end
I'm probably going to use the "origin" for others purpose.
Thanks a lot, have a good day.