Im having some serious problems with the convertToNodeSpace and convertToWorldSpace.
This is a debug project that i'm working on and i have to use convertToNodeSpace and convertToWorldSpace (or similar).
If i define two layers each has anchorpointRelative set to YES and it has a child(a button) the child has a position which is center to its layer.
(both layer has the same dimensions)
when the button is pushed i try to convert the child's position to worldSpace and then into the noseSpace of the opposite layer. And then i add the child to the opposite layer.
But what actually happens when i push the button is that the child gets moved down and to the left and added to the opposite layer.
What i expect is that the child gets gets the same position as it had in the first layer but its added to the new parent.
Im running this on the 0.99.5-beta3 with high res support.
Dev code:
-(id) init
{
// always call "super" init
// Apple recommends to re-assign "self" with the "super" return value
if( (self=[super init] )) {
CGSize size = [[CCDirector sharedDirector] winSize];
CCLabelTTF* label = [CCLabelTTF labelWithString:@"Hello World" fontName:@"Marker Felt" fontSize:64];
label.position = ccp( size.width /2 , size.height/2+200 );
[self addChild: label];
CCLayer *leftLayer = [CCColorLayer layerWithColor:ccc4(255.0, 255.0, 123.0, 128.0) width:100 height:480];
leftLayer.isRelativeAnchorPoint = YES;
leftLayer.position = ccp(50,240);
leftLayer.tag = 2001;
[self addChild:leftLayer z:0];
CCButton *leftRuta = [CCButton buttonWithImage:@"ruta_rod.png" target:self selector:@selector(rightTouch:)];
leftRuta.position = ccp(leftLayer.contentSize.width/2,leftLayer.contentSize.height/2);
debug(@"leftRuta: %@",NSStringFromCGPoint(leftRuta.position));
[leftLayer addChild:leftRuta z:10];
CCLayer *rightLayer = [CCColorLayer layerWithColor:ccc4(123.0, 255.0, 255.0, 128.0) width:100 height:480];
rightLayer.isRelativeAnchorPoint = YES;
rightLayer.tag = 1001;
rightLayer.position = ccp(320-50,240);
[self addChild:rightLayer z:0];
CCButton *rightRuta = [CCButton buttonWithImage:@"ruta_gul.png" target:self selector:@selector(rightTouch:)];
rightRuta.position = ccp(rightLayer.contentSize.width/2,rightLayer.contentSize.height/2);
debug(@"rightRuta: %@",NSStringFromCGPoint(rightRuta.position));
[rightLayer addChild:rightRuta z:10];
}
return self;
}
- (void) rightTouch:(CCButton *) sender
{
//debug(@"ruta: ws: %@ pos: %@" , NSStringFromCGPoint([sender convertToWorldSpaceAR:CGPointZero]),NSStringFromCGPoint(sender.position));
CCNode *newParent = nil;
if ( sender.parent.tag == 1001 )
newParent = [self getChildByTag:2001];
if ( sender.parent.tag == 2001 )
newParent = [self getChildByTag:1001];
sender.position = [newParent convertToNodeSpaceAR:[sender convertToWorldSpaceAR:CGPointZero]];
[sender changeToParent:newParent];
debug(@"ruta @ %@ | pos: %@",sender.parent,NSStringFromCGPoint(sender.position));
}
Images:
Pre click

Post Click
