I have a class named insect child of sprite.I have created a
instance of that class in GameLayer and then initialize with
it using,
insect *bgg = [insect spriteWithFile:@"bird2a.gif"];
then i set a timer(10 second) to change the image using
*bgg = [insect spriteWithFile:@"2.gif"];
but my program crashes.Now my question is it possible to
re-initialize an object or it is immutable??
I have another question, when i used
- (BOOL) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *) event
{
UITouch *touch = [touches anyObject];
CGPoint point2 = [touch locationInView:[touch view]];
CGPoint cpoint=[[Director sharedDirector] convertCoordinate:point2];
NSLog(@"In touch began");
}
in my insect class it cannot detect touch on ‘bgg’ object declared
in GameLayer.But when I used this function in GameLayer it can
detect touch.
whats wrong with my approach??Plz someone explain.
Advanced thanx for your reply.
Your program crashes because you have a typo. Remove the ‘*’ from ‘*bgg’. That means you are dereferencing the pointer, then trying to apply the creation of a new object to the dereferenced pointer. You just want
bgg = [insect spriteWithFile:@"2.gif"];However, it’s overkill to create an entirely new sprite just to change the image. A
Spriteis a subclass ofTextureNode, so just use TextureNode’stextureproperty to give a Sprite a different image.