I have a layer that is rotated 90 degrees that has a child sprite that is placed in the center of the screen. I want the world coordinates of the sprite’s position and I’m getting a value that’s way off than what I would expect!
Example.createScene = function() {
var scene = cc.Scene.create();
var layer = cc.Layer.create();
layer.setRotation(90);
var sprite = cc.Sprite.create("sprite.png");
// Places the sprite in the center of the screen.
sprite.setPosition(400, 300);
layer.addChild(sprite);
scene.addChild(layer);
var point = sprite.getParent().convertToWorldSpace(sprite.getPosition());
cc.log(point.x + " " + point.y); // Comes back as "-200 1100"!
return scene;
}
I should expect the result to be (400, 300). I rotated 90 degrees on an anchor point that is located on the center of the screen (I can SEE the sprite in the center of screen). However, I get (–200, 1100)!
Am I doing something wrong here or is there an issue?
Thanks!
EDIT To be thorough, if I remove the line where I rotate the layer, I get the appropriate value of (400, 300).
EDIT 2 Also I get the values I would expect if I rotated by 180 or 360. However, anything not 0, 180, or 360 is giving me odd results.