Created
February 2, 2011 17:54
-
-
Save seanh/808071 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // 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