代码之家  ›  专栏  ›  技术社区  ›  redshift5

保存/加载示例GLPaint应用程序的笔划数据的最佳方法?

  •  0
  • redshift5  · 技术社区  · 14 年前

    我注意到,默认情况下,示例应用程序GLPaint附带了一个二进制的记录数据,它在启动时加载,这是用来显示“Shake me”文本的。

    1 回复  |  直到 14 年前
        1
  •  2
  •   Jim Geldermann    14 年前

    如果你看看Recording.data 您将注意到每一行都是它自己的数组。要捕获墨迹并回放墨迹,需要有一个数组。在这个演示中-声明一个可变数组-writeray

        @synthesize writRay;
    //init in code
     writRay = [[NSMutableArray alloc]init];
    

    捕捉墨水

    // Handles the continuation of a touch.
    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    {  
    
     CGRect    bounds = [self bounds];
     UITouch*   touch = [[event touchesForView:self] anyObject];
    
     // Convert touch point from UIView referential to OpenGL one (upside-down flip)
     if (firstTouch) {
      firstTouch = NO;
      previousLocation = [touch previousLocationInView:self];
      previousLocation.y = bounds.size.height - previousLocation.y;
      /******************* create a new array for this stroke's points **************/
      [writRay addObject:[[NSMutableArray alloc]init]];
      /***** add 1st point *********/
      [[writRay objectAtIndex:[writRay count] -1]addObject:[NSValue valueWithCGPoint:previousLocation]];
     } else {
      location = [touch locationInView:self];
         location.y = bounds.size.height - location.y;
      previousLocation = [touch previousLocationInView:self];
      previousLocation.y = bounds.size.height - previousLocation.y;
      /********* add additional points *********/
      [[writRay objectAtIndex:[writRay count] -1]addObject:[NSValue valueWithCGPoint:previousLocation]];
     }
    
     // Render the stroke
     [self renderLineFromPoint:previousLocation toPoint:location];
    
    }
    

    播放墨水。

    - (void)playRay{
    
     if(writRay != NULL){
    
      for(int l = 0; l < [writRay count]; l++){
        //replays my writRay -1 because of location point
       for(int p = 0; p < [[writRay objectAtIndex:l]count] -1; p ++){
        [self renderLineFromPoint:[[[writRay objectAtIndex:l]objectAtIndex:p]CGPointValue] toPoint:[[[writRay objectAtIndex:l]objectAtIndex:p + 1]CGPointValue]];
       }
      }
     }
    }
    

    为了获得最佳效果,摇动屏幕以清除并从AppController中的changeBrushColor调用playRay。