Advertisement
Guru_stackOverFlow

Cocos2d_touch_code

Mar 16th, 2013
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import "ControlLayer2.h"
  2.  
  3. extern int CONTROL_LAYER_TAG;
  4. @implementation ControlLayer2
  5. +(id)ControlLayer2WithParentNode:(CCNode *)parentNode{
  6.     ControlLayer2 *control = [[self alloc] init];
  7.     [parentNode addChild:control z:0 tag:CONTROL_LAYER_TAG];
  8.     return control; //Guru
  9. }
  10.  
  11. -(id)init{
  12.     if (self=[super init]){
  13.     }
  14.     return self;
  15. }
  16.  
  17.  - (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
  18. {
  19.     UITouch *myTouch = [touches anyObject];
  20.     CGPoint location = [myTouch locationInView:[myTouch view]];
  21.     location = [[CCDirector sharedDirector] convertToGL:location];
  22.  
  23.     //handle touch
  24. }
  25.  
  26. @end
  27.  
  28.  
  29.  
  30. @implementation GameScene
  31.  
  32. +(id)scene{
  33.     CCScene *scene = [CCScene node];
  34.     CCLayer *layer = [GameScene node];
  35.     [scene addChild:layer z:0 tag:0];
  36.     return scene;
  37. }
  38.  
  39.  
  40. -(id)init{
  41.     if(self = [super init]){
  42.         //[[[CCDirector sharedDirector]touchDispatcher] addTargetedDelegate:[self getChildByTag:0] priority:0 swallowsTouches:YES];
  43.         //add the player layer to the game scene (this contains the player sprite)
  44.         mControlLayer2 = [ControlLayer2 ControlLayer2WithParentNode:self];
  45.         mPlayerLayer = [PlayerLayer PlayerLayerWithParentNode:self];
  46.  
  47.         self.touchEnabled = YES; //guru, in old cocos2d its self.isTouchEnabled = YES;
  48.     }
  49.     return self;
  50. }
  51.  
  52.  
  53. - (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
  54. {
  55.     [mControlLayer2 ccTouchesBegan:touches  withEvent:event];
  56.     [mPlayerLayer ccTouchesBegan:touches  withEvent:event];
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement