Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -(id) init
- {
- if( (self=[super init])) {
- CCLabelTTF *label = [CCLabelTTF labelWithString:@"Simple Line Demo" fontName:@"Marker Felt" fontSize:32];
- label.position = ccp( 240, 300 );
- [self addChild: label];
- _naughtytoucharray =[[NSMutableArray alloc ] init];
- self.isTouchEnabled = YES;
- }
- return self;
- }
- -(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
- {
- BOOL isTouching;
- // determine if it's a touch you want, then return the result
- return isTouching;
- }
- -(void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
- UITouch *touch = [ touches anyObject];
- CGPoint new_location = [touch locationInView: [touch view]];
- new_location = [[CCDirector sharedDirector] convertToGL:new_location];
- CGPoint oldTouchLocation = [touch previousLocationInView:touch.view];
- oldTouchLocation = [[CCDirector sharedDirector] convertToGL:oldTouchLocation];
- oldTouchLocation = [self convertToNodeSpace:oldTouchLocation];
- // add my touches to the naughty touch array
- [_naughtytoucharray addObject:NSStringFromCGPoint(new_location)];
- [_naughtytoucharray addObject:NSStringFromCGPoint(oldTouchLocation)];
- }
- -(void)draw
- {
- [super draw];
- ccDrawColor4F(1.0f, 0.0f, 0.0f, 100.0f);
- for(int i = 0; i < [_naughtytoucharray count]; i+=2)
- {
- CGPoint start = CGPointFromString([_naughtytoucharray objectAtIndex:i]);
- CGPoint end = CGPointFromString([_naughtytoucharray objectAtIndex:i+1]);
- ccDrawLine(start, end);
- }
- }
- - (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
- ManageTraffic *line = [ManageTraffic node];
- [self addChild: line z:99 tag:999];
- }
- - (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
- ManageTraffic *line = [ManageTraffic node];
- [self addChild: line z:99 tag:999];
- }
Add Comment
Please, Sign In to add comment