I have a class named Node,
Node is a subclass of SKNode,
I have created and added a SKShapeNode object as a child in the init method of the Node object,
But when i try to modify this child object after adding it as a child, nothing happens.
@interface Node ()
@property (nonatomic, strong) SKShapeNode *circle;
@end
@implementation Node
- (id)initWithRadius:(float)radius{
if (self = [super init]) {
_circle = [SKShapeNode shapeNodeWithCircleOfRadius:radius];
_circle.fillColor = [UIColor whiteColor];
_circle.name = @"c";
[self addChild:_circle];
}
return self;
}
//1st type of handling child object
- (void)setHighlighted{
NSLog(@"Called");
SKShapeNode *circ = (SKShapeNode *)[self childNodeWithName:@"/c"];
circ.fillColor = [SKColor redColor];
}
I also tried changing attribute of the property directly
- (void)setHighlighted{
_circle.fillColor = [SKColor redColor];
}
The setHighlighted method is being called for sure.
I even tried [_circle removeFromParent] and set position, alpha, isHidden attributes but nothing happens!!
What is the problem here?
Thanks
EDIT:
There is no problem with the code above!
Sorry the problem was: I have NSArray *nodes I was populating nodes and as they are being created I stored them in a dummy NSMutableArray *mutableNodesArray at the same time I was adding them as a child to the scene; and after the loop finished, I "copied" objects from the mutableNodesArray to the nodesArray,
so when i was trying to do operations on a Node object stored inside the nodesArray, methods were being called but these methods did not belong to the Node objects added as a child...
My mistake...