Help with mousepressed function
Posted: Sat Mar 19, 2016 7:54 pm
I just got Love like an hour ago, and I've never used Lua before, so I'm still trying to wrap my head around some of the functions. I'm trying to make a program in which, you are a sprite (yoshi) and can move around with WASD, if you press the left mouse button, then yoshi turns to mario. Just in case, the variable mega is yoshi.
Heres the code:
Heres the code:
Code: Select all
function love.load()
mega = love.graphics.newImage("yoshi.png")
var = "Use WASD to move your character around!"
mario = love.graphics.newImage("mario.png")
charx = 200
chary = 100
mario = false
end
function love.update(dt)
function love.draw()
love.graphics.print(var,300,400)
if mario == false then
love.graphics.draw(mega,charx,chary,0,0.2,0.2)
elseif mario == true then
love.graphics.draw(mario,charx,chary)
end
end
if love.keyboard.isDown("w") then
chary = chary - 10
elseif love.keyboard.isDown("s") then
chary = chary + 10
end
if love.keyboard.isDown("a") then
charx = charx - 10
elseif love.keyboard.isDown("d") then
charx = charx + 10
end
function love.mousepressed(x,y,button)
if button == '1' then
mario = true
charx = x
chary = y
end
end
end