Hey guys! Happy New Year!
I'd like to learn more about the process of adding sprites to a group. Hopefully you can help.
Suppose i have a game piece located on the stage at x:300, y:300. I scripted my game so that if you tap it, I create a group sprite, position it at x:300, y:300, add the piece to it, and set the piece's coordinates to x:0, y:0. As a result, there would be no visible change (such as movement) onscreen, but I've now added that piece to a group.
Suppose I have a second piece on the stage at x:350, y:250, which, when tapped, will be added to the group. Since I created and positioned the group sprite already, I would have expected that I would be able to add the second piece to the group, then position that piece to be x:50, y:-50 (which in theory preserves the positional relationships between the two pieces).
It's altogether possible I have a bug in my code, but that does not appear to work - one of my pieces moves up to x:0, y:0 on the stage (so it's at the upper left corner of the display) and the other one is either right on top of it or off the screen.
So: Is my understanding of how adding pieces to groups without visually altering them correct? If not, how should I be thinking of this?
One tool that may have helped me understand what's going on is the ability to set a background color or a border on the group sprite, and see how added pieces change the group sprite's dimensions. So if you would agree, I'd love to know how I could achieve that effect.
Comments
I have code that's a part of a larger project that behaves exactly as you describe (i.e., the child TextField stays at 0,0 no matter where I move the parent) but I can't seem to replicate the bad behavior when I take the code out of the larger project. Still trying to figure out what I'm doing wrong ....
--ND
But I think the functions globalToLocal and localToGlobal would be very helpful while doing these calculations. If I replace the last two lines of the example above with this:
BTW, since I posted this, I did find a few bugs in my code that made me realize that I was on the right track after all, so that's good.
Thanks again for your help. I'm pretty new to building games. I've made several attempts before on much harder game ideas in other languages/frameworks and was never able to pull it off. Thanks to the kinds of abstractions Gideros exposes, and to me picking something simpler to build, I feel like I actually have a chance to build something that I'd want to sell!