Code: Select all
Node = Object.extend(Object)
function Node:new (imgDir)
self.img = love.graphics.newImage(imgDir)
end
function Node:draw (y, scale)
-- This if works for know if a node is in the middle of the screen.
if (y + self.img:getHeight()/2)*scale < (love.graphics.getHeight()/2 + self.img:getHeight()*scale/2) and (yPosition + self.img:getHeight()/2)*scale > (love.graphics.getHeight() / 2 - self.img:getHeight()*scale / 2) then
love.graphics.setColor(102/255, 138/255, 1)
love.event.push('fixPosition', love.graphics.getHeight()/2 - (y + self.img:getHeight()/2)*scale)
love.event.push('setFocusNode', self)
end
centerX = love.graphics.getWidth() / 2 - self.img:getWidth() * scale / 2
love.graphics.draw(self.img, centerX, y * scale, 0, scale, scale)
love.graphics.setColor(1, 1, 1)
end
function Node:trigger ()
test = 0
end
Code: Select all
love.event.push('setFocusNode', self)
Code: Select all
function love.handlers.setFocusNode (node)
node:trigger()
end
Code: Select all
Error
main.lua:52: attempt to call method 'trigger' (a nil value)
Traceback
main.lua:52: in function <main.lua:51>
[C]: in function 'xpcall'
pd: node:draw() is call in the function love.draw ().