Skip to content

Instantly share code, notes, and snippets.

@seanh
Created February 2, 2011 17:54
Show Gist options
  • Select an option

  • Save seanh/808071 to your computer and use it in GitHub Desktop.

Select an option

Save seanh/808071 to your computer and use it in GitHub Desktop.
#import "cocos2d.h"
#import "Sprite.h"
@interface TargetSprite : Sprite <CCTargetedTouchDelegate> {
}
/*!
* Initialise a TargetSprite using the given dictionary.
*
* @param dict Currently dictionary should contain the key "file" with the
* filename of the file from which the sprite should be created.
*/
-(id) initWithDict:(NSDictionary *)dict;
@end
//
// TargetSprite.m
// MyGame
//
// Created by Sean Hammond on 04/11/2010.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "TargetSprite.h"
#import "GameController.h"
#import "SimpleAudioEngine.h"
@implementation TargetSprite
-(id)initWithDict:(NSDictionary *)dict
{
if( (self=[super initWithDict:dict] )) {
}
return self;
}
// Called whenever this CCNode enters the stage.
- (void)onEnter
{
// Register to receive targeted touch events.
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
[super onEnter];
}
- (void)onExit
{
[[CCTouchDispatcher sharedDispatcher] removeDelegate:self];
[super onExit];
}
- (BOOL)containsTouchLocation:(UITouch *)touch
{
return CGRectContainsPoint(spriteNode.textureRect, [spriteNode convertTouchToNodeSpace:touch]);
}
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
if ([self containsTouchLocation:touch])
{
[[SimpleAudioEngine sharedEngine] playEffect:@"pickup_coin_1.wav"];
[[GameController sharedController] endSceneWithSuccess:YES];
return YES;
}
else
{
return NO;
}
}
-(void) dealloc
{
[super dealloc];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment