Page 1 of 2

[HELP] ImagePoints

Posted: Wed Jan 21, 2015 2:59 pm
by gomez
Hello everybody,
I was wondering how to set a point(with a x,y) in an image, so when the image change your position, the point in the image also changes its position in the same proportionality.

It is possible to do in Löve ? How can i do that ?

Re: [HELP] ImagePoints

Posted: Wed Jan 21, 2015 6:21 pm
by s-ol
What? I dont understand what you mean, but I guess... Just calculate the position?

Re: [HELP] ImagePoints

Posted: Wed Jan 21, 2015 7:41 pm
by zorg
I'm guessing a simple

Code: Select all

-- use somewhere, like in love.load or another function you don't call every frame
img = love.graphics.newImage("whatever.png")
xImg = 100
yImg = 100
-- relative to image - coordinate offsets
oxPoint = 10
oyPoint = 15

-- ...

-- love.draw
love.graphics.draw(img,xImg,yImg)
-- important part
love.graphics.point(xImg+oxPoint,yImg+oyPoint)
would do it. (though this code is indeed unstructured, and a bit ugly because of that :3)

Re: [HELP] ImagePoints

Posted: Wed Jan 21, 2015 10:44 pm
by gomez
S0lll0s wrote:What? I dont understand what you mean, but I guess... Just calculate the position?
sorry, i've expressed myself badly ..(damn! google translate ¬¬' )

I wanted to create a point in an image (by point, understand something that has x and y coordinates and is relative to a image) and that this point accompany all image movements in which it is; For example, if the image moves up, this point also moves and remains in the same place relatives to the image. If the picture rotates, the point moves along
zorg wrote:I'm guessing a simple

Code: Select all

-- use somewhere, like in love.load or another function you don't call every frame
img = love.graphics.newImage("whatever.png")
xImg = 100
yImg = 100
-- relative to image - coordinate offsets
oxPoint = 10
oyPoint = 15

-- ...

-- love.draw
love.graphics.draw(img,xImg,yImg)
-- important part
love.graphics.point(xImg+oxPoint,yImg+oyPoint)
would do it. (though this code is indeed unstructured, and a bit ugly because of that :3)
Something like this, but if the point is on top of an image like a rectangle, and the rectangle rotate aside, the point does not move relatively to the image, it is stopped. I have this problem :cry:

Re: [HELP] ImagePoints

Posted: Wed Jan 21, 2015 11:03 pm
by zorg
gomez wrote:Something like this, but if the point is on top of an image like a rectangle, and the rectangle rotate aside, the point does not move relatively to the image, it is stopped. I have this problem
You never mentioned rotation though, but it should work as it is with moving the image by modifying xImg and yImg
Rotation is a bit trickier.

Re: [HELP] ImagePoints

Posted: Wed Jan 21, 2015 11:29 pm
by gomez
zorg wrote: You never mentioned rotation though, but it should work as it is with moving the image by modifying xImg and yImg
Rotation is a bit trickier.
sorry, I have explained badly my doubt ..
I wanted to make a picture orbit over another image (the two images are circles).. i'll keep trying..
thank you :ultrahappy:

Re: [HELP] ImagePoints

Posted: Thu Jan 22, 2015 1:02 am
by Ref
Pretty easy to do using a (dirty word) canvas.

Re: [HELP] ImagePoints

Posted: Thu Jan 22, 2015 1:28 am
by Evine
Like this? The 7th and 8th variable changes where it's drawn from.
https://www.love2d.org/wiki/love.graphics.draw

Code: Select all

rotation = 0
apple = love.graphics.newImage("apple.png")

function love.draw(  )
	rotation = rotation + 0.02
	love.graphics.draw(apple,400,300,rotation,1,1,45,200) -- The last 2 variable does what you want(i think).
end

Re: [HELP] ImagePoints

Posted: Thu Jan 22, 2015 10:32 am
by nfey
This is usually achieved using translation matrices. There's a bit of work to do to implement it on your own, but it's a basic requisite for 2d video games so there are quite a few tutorials out there explaining how to achieve it. https://en.wikipedia.org/wiki/Translati ... eometry%29

As far as I know, the only existing Love functionality that can help with this is in the love.physics module. https://www.love2d.org/wiki/Body:getWorldPoints
But unless you actually need physics support in your game, it makes no sense to start creating bodies and fixtures just so you can use the transformation logic.

Re: [HELP] ImagePoints

Posted: Thu Jan 22, 2015 2:55 pm
by s-ol
nfey wrote:This is usually achieved using translation matrices. There's a bit of work to do to implement it on your own, but it's a basic requisite for 2d video games so there are quite a few tutorials out there explaining how to achieve it. https://en.wikipedia.org/wiki/Translati ... eometry%29

As far as I know, the only existing Love functionality that can help with this is in the love.physics module. https://www.love2d.org/wiki/Body:getWorldPoints
But unless you actually need physics support in your game, it makes no sense to start creating bodies and fixtures just so you can use the transformation logic.
I doubt he even needs to calculate it, drawing might be enough already.