Reputation: 21899
First of all thumbs up to Nicolas for his great engine.
What I a doing is... 1) I created a sprite, lets call is a parent sprite 2) I created another sprite, lets call it child sprite 3) I set child positing using convertLocalToSceneCoordinates 4) I rotated this child sprite to -90 degree 5) I Added this sprite to parent sprite and finally added parent sprite to scene
Now its looking fine and moving along with parent but when I try to add another sprite at the position of child sprite it give me wrong coordinates. i.e X and Y.
Please tell me how to fix?
code:
mRocketPod = new RocketPod(0, 0, this.mTRRocketPod);
float points[] = mRocketPod.convertLocalToSceneCoordinates(119, 10);
mRocketPod.setPosition(points[0], points[1]);
mRocketPod.setRotation(-90);
mBossEarth.attachChild(mRocketPod);
It will give me wrong coordinates of mRocketPod.
Upvotes: 0
Views: 1716
Reputation: 3444
Let me confirm my understanding here. I'm interpreting your question as mBossEarth and mRocketPod as 2 different sprites, and the relationship between the 2 is that mRocketPod is the child sprite under mBossEarth, as I can see from mBossEarth.attachChild(mRocketPod).
I think the faulty statement is this:
float points[] = mRocketPod.convertLocalToSceneCoordinates(119, 10);
1) If you have the scene coordinates for which mRocketPod is supposed to be attached to, but you wish to establish it as a child of mBossEarth, you should be getting the local coordinates of mBossEarth, and then setting mRocketPod to that position before attaching it to mBossEarth. What you did is to convert (119, 10) of your sprite mRocketPod into the scene coordinates, and when you mistakenly apply this scene coordinates to setPosition and attach to the parent, you will be waayyyy off your intended position. Correct code should be something like this:
mRocketPod = new RocketPod(0, 0, this.mTRRocketPod);
float points[] = mBossEarth.convertSceneToLocalCoordinates(119, 10);
mRocketPod.setPosition(points[0], points[1]);
mRocketPod.setRotation(-90);
mBossEarth.attachChild(mRocketPod);
In the proposed solution, what I'm doing is to convert the scene coordinates you have into the coordinate system within mBossEarth. This way, when you attach child, it will be set to the position within mBossEarth.
2) In the unlikely event that you actually have the coordinates within mBossEarth you want to position mRocketPod at, which is (119, 10), you can actually directly set it in your constructor without having to do any coordinate conversion. Correct code is probably this:
mRocketPod = new RocketPod(119, 10, this.mTRRocketPod);
mRocketPod.setRotation(-90);
mBossEarth.attachChild(mRocketPod);
Upvotes: 2