[HELP] ImagePoints

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
gomez
Citizen
Posts: 65
Joined: Mon Feb 18, 2013 12:23 am
Location: Sao Luís, Brazil

[HELP] ImagePoints

Post 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 ?
Last edited by gomez on Wed Jan 21, 2015 10:33 pm, edited 2 times in total.
Hey dude :D
Do you want to protect earth from an apocalypse ? Me too o/
Check my new game here: viewtopic.php?f=5&t=81001
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: [HELP] ImagePoints

Post by s-ol »

What? I dont understand what you mean, but I guess... Just calculate the position?

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
zorg
Party member
Posts: 3453
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: [HELP] ImagePoints

Post 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)
Me and my stuff :3True 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.
User avatar
gomez
Citizen
Posts: 65
Joined: Mon Feb 18, 2013 12:23 am
Location: Sao Luís, Brazil

Re: [HELP] ImagePoints

Post 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:
Hey dude :D
Do you want to protect earth from an apocalypse ? Me too o/
Check my new game here: viewtopic.php?f=5&t=81001
User avatar
zorg
Party member
Posts: 3453
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: [HELP] ImagePoints

Post 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.
Me and my stuff :3True 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.
User avatar
gomez
Citizen
Posts: 65
Joined: Mon Feb 18, 2013 12:23 am
Location: Sao Luís, Brazil

Re: [HELP] ImagePoints

Post 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:
Hey dude :D
Do you want to protect earth from an apocalypse ? Me too o/
Check my new game here: viewtopic.php?f=5&t=81001
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: [HELP] ImagePoints

Post by Ref »

Pretty easy to do using a (dirty word) canvas.
User avatar
Evine
Citizen
Posts: 72
Joined: Wed May 28, 2014 11:46 pm

Re: [HELP] ImagePoints

Post 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
Attachments
blah.love
(7.26 KiB) Downloaded 50 times
Artal, A .PSD loader: https://github.com/EvineDev/Artal
User avatar
nfey
Citizen
Posts: 63
Joined: Tue Feb 18, 2014 9:50 am
Location: Romania

Re: [HELP] ImagePoints

Post 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.
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: [HELP] ImagePoints

Post 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.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 5 guests