I know I am missing something completely fundamental and obvious, but Im getting why this doesnt work and I have gone thru quite a few examples and videos and I am only getting more confused.
--create our tables, image here is just a name
myImage={}
mouse={}
--loads our myImages
function love.load()
myImage.image = love.graphics.newImage("hand.png")
myImage.background= love.graphics.newImage("800x600.jpg")
-- here I define hero as a image
hero= love.graphics.newImage("hero.png")
movex=0
movey=0
stepx=0
stepy=0
end
function love.mousereleased(x, y, button)
if button == 1 then
movex=x
movey=y
end
end
--get our mouse position
function love.update()
love.mouse.setVisible( false )
mouse.x, mouse.y = love.mouse.getPosition()
-- here is where the bug occurs
if hero.x < mouse.x then stepx=stepx+4
end
end
function love.draw()
--draw background
love.graphics.draw(myImage.background,0,0)
--draw image to mouse position
love.graphics.draw(myImage.image,mouse.x-40,mouse.y-10)
--draw hero and move towards
love.graphics.draw(hero,stepx,stepy)
end
I am assuming somehow hero.x is nil- but I dont know why its nil. Wanting to check hero.x position in relation mouse.x position.
So how to create the hero reference in such a way I can see and check coordinates etc?
jbskaggs wrote: ↑Tue Dec 15, 2020 6:09 pm
So you create a table and add variables to it. X and y are not set, but is x and y reserved variables that always refer to 2d coordinates?
No, they are not reserved, nor is anything else; you creating an Image object doesn't automatically allow you to access its position (or any other parameter) just by doing something like hero.x (and images don't even store positions).
Feel free to look at the wiki, it tells you what objects support what methods that can get you some pieces of data - like image:getWidth(), image:getHeight(), image:getDimensions() - since it's super useful.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Thanks that is helpful. Like I said I was getting lost in the wiki and videos. But these replies are very illuminating for me as in GML x and y were reserved and it was biasing my thinking.