Code: Select all
save_icon.dragging = {active = false , diffX = 0 , diffY = 0}
how-come?
Code: Select all
save_icon.dragging = {active = false , diffX = 0 , diffY = 0}
For what it is worth, hope this will help figure out.Echo wrote:solved the problem, no more error messages BUT there is no effect when I try dragging and dropping the save icon.Code: Select all
save_icon.dragging = {active = false , diffX = 0 , diffY = 0}
how-come?
Code: Select all
function love.load()
collide = function(o1x,o1y,o1w,o1h,o2x,o2y,o2w,o2h)
return not ((o2x > o1x + o1w) or (o2x + o2w < o1x) or
(o2y > o1y + o1h) or (o2y + o2h < o1y))
end
obj = { x = 10, y = 10, w = 50, h = 50}
obj.onDragging = false
obj.dPos = { x = obj.x, y = obj.y}
end
function love.update(dt)
mx,my = love.mouse.getPosition()
if obj.onDragging then
obj.x = mx - obj.dPos.x
obj.y = my - obj.dPos.y
end
end
function love.draw()
love.graphics.rectangle('line',obj.x,obj.y,obj.w,obj.h)
end
function love.mousepressed(x,y,button)
if button == 'l' then
obj.onDragging = collide(x,y,1,1,obj.x,obj.y,obj.w,obj.h)
if obj.onDragging then
obj.dPos.x = (x - obj.x)
obj.dPos.y = (y - obj.y)
end
end
end
function love.mousereleased(x,y,button)
if button == 'l' then obj.onDragging = false end
end
Code: Select all
if ( button == "1" )
and ( x > save_icon.x > x ) and ( x < save_icon.x + save_icon.width )
and ( y > save_icon.y > y ) and ( y < save_icon.y + save_icon.height )
then
save_icon.dragging.active = true
save_icon.dragging.diffX = ( x - save_icon.x )
save_icon.dragging.diffY = ( y - save_icon.y )
end
Code: Select all
a > b > c
Code: Select all
(true|false) > b
Code: Select all
if ( button == "l" )
and ( x > save_icon.x ) and ( x < save_icon.x + save_icon.width )
and ( y > save_icon.y ) and ( y < save_icon.y + save_icon.height )
then ...
end
It could be as simple as:Echo wrote: One more thing related to the drag and drop.
How can I set an image to destroy itself once the mouse has been released.
Code: Select all
function love.draw()
if save_icon.dragging.active then love.graphics.draw(save_icon.image,save_icon.x,save_icon.y) end
end
Are you sure about that ?Echo wrote:It saves fine and the serialization is fine but when I try loading the game nothing happens.
Code: Select all
...
save = {}
save.state = false
...
load = {}
load.state = false
...
if ( save.state == true ) then
function save(data)
love.filesystem.write('sav',_tostring(data))
end
end
if ( load.state == true ) then
function load(file)
return love.filesystem.load(file)()
end
end
...
Code: Select all
run love.load() --only once
-- run in loop
while running do
process_events()
love.update()
love.draw()
end
Code: Select all
if ... and ( save_icon.x > note.x ) and ( save_icon.x < note.x + note.width )
and ( save_icon.y > note.y ) and ( save_icon.y < note.y + note.height )
Code: Select all
setmetatable(save, {__call = save_function})
setmetatable(load, {__call = load_function})
Users browsing this forum: Bing [Bot] and 9 guests