Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jan 4th, 2013  |  syntax: None  |  size: 1.84 KB  |  views: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. -(id) init
  2. {
  3.     if( (self=[super init])) {
  4.  
  5.  
  6.         CCLabelTTF *label = [CCLabelTTF labelWithString:@"Simple Line Demo" fontName:@"Marker Felt" fontSize:32];
  7.         label.position =  ccp( 240, 300 );
  8.         [self addChild: label];
  9.  
  10.         _naughtytoucharray =[[NSMutableArray alloc ] init];
  11.  
  12.          self.isTouchEnabled = YES;
  13.  
  14.  
  15.     }
  16.     return self;
  17. }
  18.  
  19. -(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
  20. {
  21.     BOOL isTouching;
  22.     // determine if it's a touch you want, then return the result
  23.     return isTouching;
  24. }
  25.  
  26.  
  27. -(void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event  {
  28.     UITouch *touch = [ touches anyObject];
  29.     CGPoint new_location = [touch locationInView: [touch view]];
  30.     new_location = [[CCDirector sharedDirector] convertToGL:new_location];
  31.  
  32.     CGPoint oldTouchLocation = [touch previousLocationInView:touch.view];
  33.     oldTouchLocation = [[CCDirector sharedDirector] convertToGL:oldTouchLocation];
  34.     oldTouchLocation = [self convertToNodeSpace:oldTouchLocation];
  35.     // add my touches to the naughty touch array
  36.     [_naughtytoucharray addObject:NSStringFromCGPoint(new_location)];
  37.     [_naughtytoucharray addObject:NSStringFromCGPoint(oldTouchLocation)];
  38. }
  39. -(void)draw
  40. {
  41.     [super draw];
  42.     ccDrawColor4F(1.0f, 0.0f, 0.0f, 100.0f);
  43.     for(int i = 0; i < [_naughtytoucharray count]; i+=2)
  44.     {
  45.         CGPoint start = CGPointFromString([_naughtytoucharray objectAtIndex:i]);
  46.         CGPoint end = CGPointFromString([_naughtytoucharray objectAtIndex:i+1]);
  47.         ccDrawLine(start, end);
  48.  
  49.     }
  50. }
  51. - (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
  52.     ManageTraffic *line = [ManageTraffic node];
  53.     [self addChild: line z:99 tag:999];
  54. }
  55.        
  56. - (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
  57.  
  58.     ManageTraffic *line = [ManageTraffic node];
  59.     [self addChild: line z:99 tag:999];
  60. }