Page 2 of 2

Re: rotate an image in the direction of the mouse

Posted: Tue Jun 24, 2014 10:25 am
by Heeloo
I have edited but I am getting the same error.

Code: Select all

local zombo = require "zombo"
local man = require "man"

function love.load()
	man.load()
	zombo.load()
end



function love.update(dt)
	findRotation = math.atan2(mouseY - many, mX - manx)
	man.update()
	mouseY = love.mouse.getY()
end

function love.keypressed(key)
	if key == "escape" then
		love.event.quit()
	end

end

function love.draw()
	man.draw()
	zombo.draw()
end
the error I get is

main.lua:12: attempt to perform arithmetic on global 'mouse Y' (a nil value)

Re: rotate an image in the direction of the mouse

Posted: Tue Jun 24, 2014 1:00 pm
by Plu
During the very first frame, you only load the mouseY variable after trying to use it. You need to either move up the line where you set the mouseY, or you need to initialize it with some kind of default value. (I think in this case it should be the former)