Ok im desperate..
This is what I want do to: I have a layer that have 3 sprites, a bottom one with the upper part of a match box, a middle one a Custom CCLayer with the image of a match, and a top one a sprite with the image of the matchbox cover. so it looks like the matchbox is open and there is one match ready to pull.
I subclass CCLayer to add the match sprite, and then allow movement of this layer (single match). I did this:
-(id)copyWithZone:(NSZone *)zone{
YEMatchSprite * copyMatch = [[[self class] allocWithZone:zone] init];
[copyMatch set_parentScene:self._parentScene];
return copyMatch;
}
-(id)init{
self = [super init];
if(self){
self.contentSize = CGSizeMake (50,174);
CCSprite * matchSprite = [CCSprite spriteWithFile:@"match.png"];
matchSprite.position = ccp (self.contentSize.width/2, self.contentSize.height/2);
[self addChild:matchSprite];
inBox = YES;
self.isTouchEnabled = YES;
}
return self;
}
now in my ccTouchBegan I have the following as a test.
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *myTouch = [touches anyObject];
CGPoint location = [myTouch locationInView:[myTouch view]];
NSLog(@"loc before %f,%f", location.x, location.y);
location = [[CCDirector sharedDirector] convertToGL:location];
NSLog(@"loc after %f,%f", location.x, location.y);
}
why even if I click outside this layer, let say somewhere in the scene, this method above still gets called?
I tried using instead the [[CCTouchDispatcher,, and I have the same results.
My custom ayer has a ivar assignation to the main scene, for a this reason.
When I enter the moved event I call the main scene, and this one copies the layer, then add the copy to itself and then move the copy to the location its being told by parameter.
So its working 50-50, I can click the match and then it moves the match over the scene. but I can click anywhere in the scene and it will still move the match with its in the Box. Then it happens what I explain in the first post.
Any suggestions
Thanks