home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Internet / News / Alexandra.0.82 / Source / Info.subproj / Sequence.m < prev   
Encoding:
Text File  |  1996-01-30  |  1.8 KB  |  105 lines

  1.  
  2. #import "Sequence.h"
  3.  
  4. @implementation Sequence:Object
  5.  
  6. //-----------------------------------------------------------
  7. //    SET UP 
  8. //-----------------------------------------------------------
  9.  
  10. - setFrameCount:(int)frames;        
  11.     {
  12.     frameCount=frames;
  13.     return self;
  14.     }
  15.     
  16.  
  17. - setLocation:(const NXPoint *)aPoint;
  18.     {
  19.     where=*aPoint;
  20.     return self;
  21.     }
  22.     
  23.  
  24. - setImage:(NXImage *)anImage;        
  25.     {
  26.     image=anImage;
  27.     [image getSize:&imageSize];
  28.     frameSize=imageSize;
  29.     frameSize.height/=frameCount;
  30.     return self;
  31.     }
  32.  
  33.  
  34. - setBounce:(BOOL)flag;    
  35.     {
  36.     bounce=flag;
  37.     return self;
  38.     }
  39.  
  40.  
  41. //-----------------------------------------------------------
  42. //    PLAY
  43. //-----------------------------------------------------------
  44.  
  45. - start:controlView;
  46.     {
  47.     currentFrame=-1;
  48.     direction=FORWARD;
  49.     return [self nextFrame:controlView];
  50.     }
  51.  
  52.  
  53. - nextFrame:controlView;
  54.     {
  55.     currentFrame+=direction;
  56.     if(direction==FORWARD)
  57.         {
  58.         if(currentFrame>=frameCount)
  59.             if(bounce)
  60.                 {
  61.                 direction=BACKWARDS;
  62.                 currentFrame--;
  63.                 }
  64.             else
  65.                 {
  66.                 direction=STOPPED;
  67.                 currentFrame=0;
  68.                 }
  69.         }
  70.     else
  71.         {
  72.         if(currentFrame==0)
  73.             direction=STOPPED;
  74.         }
  75.     [controlView lockFocus];
  76.     [self compositeFrame:currentFrame];
  77.     [controlView unlockFocus];
  78.     [[controlView window] flushWindow];
  79.     if(direction!=STOPPED)
  80.         [self perform:@selector(nextFrame:) with:controlView 
  81.                                 afterDelay:100 cancelPrevious:NO];
  82.     return self;
  83.     }
  84.  
  85.  
  86. //-----------------------------------------------------------
  87. //    DRAW!
  88. //-----------------------------------------------------------
  89.  
  90. - compositeFrame:(int)no;
  91.     {
  92.     NXRect    what={0,0,frameSize.width,frameSize.height};
  93.     
  94.     what.origin.y=imageSize.height-((no+1)*frameSize.height);
  95.     [image composite:NX_SOVER fromRect:&what toPoint:&where];
  96.     return self;
  97.     }
  98.  
  99.  
  100. //-----------------------------------------------------------
  101. //    THAT'S IT
  102. //-----------------------------------------------------------
  103.  
  104. @end
  105.