ok, So here is the situation:
I have a FoodMenu:Menu class since i need to overwrite the touch functions.
'@property(nonatomic, retain) Texture2D* selected;
-(id) init
{
MenuItemImage* apple = [MenuItemImage itemFromNormalImage:@"food_healthy_apple.png" selectedImage:@"food_healthy_apple.png" target:self selector:@selector(giveapple:)];
self = [[FoodMenu menuWithItems:apple, nil] retain];
[self alignItemsInColumns:[NSNumber numberWithUnsignedInt:3],[NSNumber numberWithUnsignedInt:3], nil];
selected = nil;
worldItem = nil;
world = [World sharedWorld];
return self;
}
-(void) giveapple: (id)sender
{
if(selected)
[selected release];
selected = nil;
selected = [[TextureMgr sharedTextureMgr] addImage:@"food_healthy_apple.png"];
}
-(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
if(self.visible == NO) return NO;
[super ccTouchBegan:touch withEvent:event];
if(!selectedItem)
{
self.visible = NO;
return NO;
}
//[selectedItem activateWithTarget:self];
[selectedItem activate];
return YES;
}'
It seems instead of copy pointer, the invocation create an copy of the actual instance of the target. Ive test it by create a func call activeWithTarget in MenuItem
'-(void) activateWithTarget:(id)target
{
if(isEnabled)
[invocation invokeWithTarget:target];
}'
if I use the function invoke, variable selected will return to nil after giveapple finished since all the change was in another instance.
Things works fine with activateWithTarget.
Is this a bug? Can anyone clarify this for me?
Cheers