It looks like you're new here. If you want to get involved, click one of these buttons!
local ns = Sprite.new() stage:addChild(ns) ns:setPosition(150,0) stage:setPosition(-150,0) print (ns:getPosition()) --prints 150 0 print (ns:localToGlobal(ns:getPosition())) --prints 150 0 print (ns:globalToLocal(ns:getPosition())) --prints 150 0 |
Comments
@Atilim: this seems to be a bug, or?
By passing the coordinates of the ns sprite you are getting that position in ns sprite converted. So it's adding 150 to 150 etc.
At least I think that's whats going on here.
I believe that globalToLocal and localToGlobal don't care about parent sprites and returns the x,y relative to the logical resolution.
I could be wrong again though I'm trying to create a detailed example for my own understanding.
edit: updated and cleaned example to not confuse anyone:
So it doesn't matter what sprite manipulation you do by setPosition (which takes place relative to the parent sprite) - Global means where it actually appears to the user on the device.
I'm not sure what you mean that setPosition doesn't matter since you need to use it to keep the image in the same position after moving between sprites?
I think Gideros knows what you want to do when you combine setPosition and globalToLocal together?
so you get 50 (I think)
cheers
evs
Likes: avo
Something that does bother me is that if you do:
If you stop the program after adding blue to the stage, then it does not appear on the device, because it's at -50,-50.
edit: oh I think I should have used "visual position" earlier when I was saying it was in the "same position" I meant when you look at the actual device.
To me it's working as it should, apart from that one print statement where I think it should be -50, and not 0.
The magic bit I had there was just because I was printing the gTL function after I had already changed the images position, duh #-o
edit: I think this might also hopefully explain the issue that started this thread.
And now I must apologize to everyone for posting so many times in this thread, I hope some of it is coherent at least :P
I think the real confusion is this usage:
Likes: Holonist
So I made it work and then tried to figure out why exactly it worked that way #-o
anyway thank you atilim. I think I'll edit a couple of my posts so as not to confuse future readers.
I don't know what I was thinking. I'll also correct that post.
thank you avo.
Is there something else I'm doing wrong, because it does seem like you need to pass in the position like I was doing?
Passing the position uses the position of sprite twice while doing the calculations. Therefore this usage should always give wrong results.
What is the result if you change the line:
thank you for clearing this up atilim.
Here is a cleaned up example if anyones curious or seeing this later:
Improving the reference manual is good idea. I'll do it.
thanks
Likes: avo, seppsepp